If statement Lua Tween零件信息
我正在制作一个tween,它使用一个人形坐姿事件提供的数据,我想让相机在坐下时移到终点,但是,在他们坐起来后移回终点。我觉得问题出在零件信息上,但我可能错了 代码如下: 发送方/事件处理程序:If statement Lua Tween零件信息,if-statement,events,lua,roblox,tween,If Statement,Events,Lua,Roblox,Tween,我正在制作一个tween,它使用一个人形坐姿事件提供的数据,我想让相机在坐下时移到终点,但是,在他们坐起来后移回终点。我觉得问题出在零件信息上,但我可能错了 代码如下: 发送方/事件处理程序: local camPart = script.Parent local camEvent = game.ReplicatedStorage.CamEvent local blueSeat = script.Parent.Parent.BlueSeat.Seat --the correct seat per
local camPart = script.Parent
local camEvent = game.ReplicatedStorage.CamEvent
local blueSeat = script.Parent.Parent.BlueSeat.Seat --the correct seat person should be in
local bluePlayerName = script.Parent.Parent.Buttons.BlueEnter.PlayerName --the supposed name of person
bluePlayerName:GetPropertyChangedSignal("Value"):Connect(function ()
if (bluePlayerName ~= "") then
local char = game.Workspace:FindFirstChild(bluePlayerName.Value, true)
local player = game.Players:GetPlayerFromCharacter(char)
char.Humanoid.Seated:Connect(function (isSeated, seat)
if (seat.Name == blueSeat.Name) then
camEvent:FireClient(player, camPart, isSeated) --go to tween handler
end
end)
end
end)
接收器/吐温处理器:
local TweenService = game:GetService("TweenService")
local cam = game.Workspace.Camera
local partData
local tween
local length = 2
local tweenData = TweenInfo.new(
length,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
script.Parent.OnClientEvent:Connect(function (camPart, isSeated) --receiver
partData = {
CFrame = camPart.CFrame
}
tween = TweenService:Create(cam, tweenData, partData)
if (isSeated == true) then
cam.CameraType = Enum.CameraType.Scriptable --remove control
tween:Play()
wait(length / 2)
tween:Pause() --stop at end point
elseif (isSeated == false) then
tween:Play() --go back/finish
wait(length / 2)
cam.CameraType = Enum.CameraType.Custom --give control back
end
end)
RemoteEvent根本没有触发这一事实应该是服务器脚本中没有连接到Humanoid.Seated事件的线索。从您的代码示例中不清楚什么会首先触发代码,但看起来您只是在寻找玩家的角色何时加载到工作区 我建议使用或事件作为访问玩家角色和类人角色的方式。您仍然可以使用您的UI代码作为是否切换的触发器,但这可能更容易
-- Server Script
local camPart = script.Parent
local camEvent = game.ReplicatedStorage.CamEvent
local thing = script.Parent.Parent
local blueSeat = thing.BlueSeat.Seat --the correct seat person should be in
local bluePlayerName = thing.Buttons.BlueEnter.PlayerName --the supposed name of person
-- listen for when a player sits in a seat
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Humanoid.Seated:Connect(function(isSeated, seat)
print("Player is seated?", isSeated)
if not isSeated then
-- tell the client to zoom out
camEvent:FireClient(player, camPart, isSeated)
else
-- decide whether to tween the camera
local isApprovedSeat = seat.Name == blueSeat.Name
local isNameSet = bluePlayerName.Value ~= ""
local shouldTweenCamera = isApprovedSeat and isNameSet
if shouldTweenCamera then
camEvent:FireClient(player, camPart, isSeated)
else
local message = table.concat({
"Camera not tweening because: ",
"Player has claimed this seat? " .. tostring(hasClaimedSeat),
"This is the approved seat? " .. tostring(isApprovedSeat)
}, "\n")
warn(messsage)
end
end
end)
end)
end)
此外,侦听此RemoteEvent的LocalScript似乎位于ReplicatedStorage中。请注意,它们只在少数几个位置发射,不幸的是,ReplicatedStorage不在其中。尝试将LocalScript移动到StarterCharacterScript中,并更新RemoteEvent的路径
local camEvent = game.ReplicatedStorage.CamEvent
camEvent.OnClientEvent:Connect(function (camPart, isSeated) --receiver
Heyo Killerrerderp7,你说了你想做的,但你没有说不起作用的。一点也不讨厌吗?进入坐姿相机视图的tween是否正常工作,但一旦完成就不会返回?连接tween脚本的事件没有被调用*我已经查看了代码,我知道该事件正在传递(我在事件调用后放入了一条打印语句,它被激发),我想问题出在接收方,但我不确定到底出了什么错哦哦我的错。我忽略了LocalScript的位置。我会更新我的答案。谢谢你的帮助,不过我只是在检查通知之前解决了这个问题