0

I want to make a game but there is something problem with it; I can't make the player sit for the game to start

I tried to improve the code and I thought improving it would work but it didn't work

I put the code in Script "Script"

Here's the code:

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

1 Answers1

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

sending event to server from client, using FireServer... & add break; this is not perfect idea, maybe you can edit or add some more codes.

NormalToad
  • 73
  • 5