简体   繁体   English

Lua 补间部分信息

[英]Lua Tween Part Info

I am making a tween that uses data given from a Humanoid.Seated event, and I wanted to make the camera go to the end point when sat down, however, move back after they sat up.我正在制作一个使用 Humanoid.Seated 事件提供的数据的补间,我想让相机 go 在坐下时到达终点,但是,在他们坐起来后移回。 I have a feeling that the problem is with the part info, however I could be wrong.我感觉问题出在零件信息上,但是我可能是错的。

This is the code:这是代码:

The Sender/Event Handler:发件人/事件处理程序:

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)

The Receiver/Tween Handler:接收器/补间处理程序:

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)

The fact that the RemoteEvent isn't firing at all should be an clue that the connection to the Humanoid.Seated event isn't being reached in the server Script. RemoteEvent 根本没有触发的事实应该表明服务器脚本中没有达到与 Humanoid.Seated 事件的连接。 It's unclear from your code sample what would trigger the code in the first place, but it looks like you're just looking for when a player's character loads into the workspace.从您的代码示例中不清楚什么会首先触发代码,但看起来您只是在寻找玩家角色何时加载到工作区中。

I would recommend using the Player.CharacterAdded or Player.CharacterAppearanceLoaded events as ways of getting access to the player's Character and humanoid.我建议使用Player.CharacterAddedPlayer.CharacterAppearanceLoaded事件作为访问玩家角色和类人机器人的方法。 You can still use your UI code as a trigger for whether to tween or not, but it might be easier.您仍然可以使用您的 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)

Also, it looks like the LocalScript that is listening for this RemoteEvent is located in ReplicatedStorage.此外,侦听此 RemoteEvent 的 LocalScript 似乎位于 ReplicatedStorage 中。 Check the documentation on LocalScripts , they only fire in a handful of locations, and ReplicatedStorage unfortunately isn't one of them.查看LocalScripts 上的文档,它们只在少数几个位置触发,不幸的是 ReplicatedStorage 不是其中之一。 Try moving the LocalScript into StarterCharacterScripts and update the path to the RemoteEvent.尝试将 LocalScript 移动到 StarterCharacterScripts 并更新 RemoteEvent 的路径。

local camEvent = game.ReplicatedStorage.CamEvent
camEvent.OnClientEvent:Connect(function (camPart, isSeated) --receiver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM