由于某种原因,我的代码无法让我的玩家坐下,我需要一个解决方案

问题描述 投票:0回答:2

我想做一个游戏,但有一些问题;我无法让玩家坐下来等待游戏开始

我尝试改进代码,我认为改进它会起作用,但它不起作用

我把代码放在脚本“Script”中

这是代码:

if player then
    local BusSeats = workspace.Bus.Seats:GetChildren()

    local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid.JumpPower = 0

        for i, v in ipairs(BusSeats) do
            if not v.Occupant then
                v:Sit(humanoid)
                ReplicatedStorage.GetOnQueue:FireClient(player)
            end
        end
    end
end
lua roblox luau
2个回答
0
投票
-- Assuming this script is placed in a LocalScript
local player = game.Players.LocalPlayer

if player then
    local BusSeats = workspace.Bus.Seats:GetChildren()

    local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid.JumpPower = 0

        for i, v in ipairs(BusSeats) do
            if not v.Occupant then
                v:Sit(humanoid)
                break -- Exit the loop after sitting on the first available seat
            end
        end

        -- Call the GetOnQueue RemoteEvent to notify the server that the player has sat on a seat
        game.ReplicatedStorage.GetOnQueue:FireServer()
    end
end

使用 FireServer...从客户端向服务器发送事件并添加 break; 这不是完美的想法,也许您可以编辑或添加更多代码。


0
投票

制作一个座位对象。如果玩家触摸它,就会自动坐下。

© www.soinside.com 2019 - 2024. All rights reserved.