Lua 补间零件信息

我正在制作一个使用 Humanoid.Seated 事件提供的数据的补间,我想让相机在坐下时移动到终点,但是,在他们坐起来后移回。我感觉问题出在零件信息上,但我可能是错的。

这是代码:

发送方/事件处理程序:

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,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)
PIAOPIAOXUEYAOCHAOXI 回答:Lua 补间零件信息

RemoteEvent 根本没有触发的事实应该表明服务器脚本中没有到达 Humanoid.Seated 事件的连接。从您的代码示例中并不清楚首先什么会触发代码,但看起来您只是在寻找玩家角色加载到工作区的时间。

我建议使用 Player.CharacterAddedPlayer.CharacterAppearanceLoaded 事件作为访问玩家角色和人形生物的方式。您仍然可以使用您的 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,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 中。检查 the documentation on LocalScripts,它们只在少数几个位置触发,不幸的是 ReplicatedStorage 不是其中之一。尝试将 LocalScript 移动到 StarterCharacterScripts 并更新 RemoteEvent 的路径。

local camEvent = game.ReplicatedStorage.CamEvent
camEvent.OnClientEvent:Connect(function (camPart,isSeated) --receiver
本文链接:https://www.f2er.com/885191.html

大家都在问