Lua Tween 部件信息

我正在制作一个 tween,它使用从 Humanoid.Seated 事件获取的数据,并且我想在坐下时让相机到达终点,然后在他们起身后后退。我觉得问题可能出在部件信息上,但我可能错了。

这是代码:

发送器/事件处理程序:

local camPart = script.Parent
local camEvent = game.ReplicatedStorage.CamEvent
local blueSeat = script.Parent.Parent.BlueSeat.Seat --人应该坐在正确的座位上

local bluePlayerName = script.Parent.Parent.Buttons.BlueEnter.PlayerName --人的假定姓名

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) --转到 tween 处理程序
            end
        end)
    end
end)

接收器/tween 处理程序:

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) --接收器

    partData = {
        CFrame = camPart.CFrame
    }

    tween = TweenService:Create(cam, tweenData, partData)

    if (isSeated == true) then

        cam.CameraType = Enum.CameraType.Scriptable --删除控件
        tween:Play()

        wait(length / 2)
        tween:Pause() --停在终点

    elseif (isSeated == false) then

        tween:Play() --返回/完成
        wait(length / 2)

        cam.CameraType = Enum.CameraType.Custom --归还控制
    end
end)
点赞
用户2860267
用户2860267

提示 RemoteEvent 没有触发的事实应该表明在服务端脚本中未到达 Humanoid.Seated 事件的连接点。从你提供的代码示例中无法理解何时触发代码,但看起来你只是在等待玩家角色加载到工作区。

我建议使用 Player.CharacterAdded 或者 Player.CharacterAppearanceLoaded 事件来获取玩家的角色和人形。你仍然可以使用你的 UI 代码作为触发器来执行缓动效果,但这样可能更容易。

-- 服务端脚本
local camPart = script.Parent
local camEvent = game.ReplicatedStorage.CamEvent
local thing = script.Parent.Parent
local blueSeat = thing.BlueSeat.Seat -- 应该有人坐的正确座位
local bluePlayerName = thing.Buttons.BlueEnter.PlayerName -- 人名

-- 监听玩家坐在座位上
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character.Humanoid.Seated:Connect(function(isSeated, seat)
            print("玩家坐下了?", isSeated)
            if not isSeated then
               -- 让客户端缩放镜头
               camEvent:FireClient(player, camPart, isSeated)
            else

                -- 决定是否缓动镜头
                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 中。请查看 LocalScripts 的文档,它们只存在于一些特定位置中,而 ReplicatedStorage 不幸不是其中之一。请将 LocalScript 移到 StarterCharacterScripts 并更新 RemoteEvent 的路径。

local camEvent = game.ReplicatedStorage.CamEvent
camEvent.OnClientEvent:Connect(function (camPart, isSeated) -- 接收端
2021-02-22 00:24:44