Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I have a problem with my script when I add players to a table. I'm not getting any errors.?

Asked by 4 years ago

I have 2 scripts: Client and server

The problem is on my server script, where I can't add players to a table

local PlayersToTeleport = {}


game.ReplicatedStorage:WaitForChild("MoveBus").OnServerEvent:Connect(function(plr, randomSeat)

randomSeat.Touched:Connect(function(TouchedPart)
    if TouchedPart.Parent:FindFirstChild("Humanoid") then
        local Character = TouchedPart.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        local AlreadyInTable = false
        for _,OtherPlayer in next,PlayersToTeleport do
            if OtherPlayer == Player then
                AlreadyInTable = true
            end
        end
        if not AlreadyInTable then
        table.insert(PlayersToTeleport,Player)
        end
    end
end)

Can you help me fix it?

0
And you fire the MoveBus event? herrtt 387 — 4y
0
Use print()'s to determine where the function is running and where it is not running. It will help you out a ton. DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago

Is this what you where attempting to accomplish?

local PlayersToTeleport = {}

local seat = game.ReplicatedStorage:WaitForChild("MoveBus")
local random = math.random(1,#seat)

random.Touched:Connect(function(plr)
    if plr.Character:FindFirstChild("Humanoid") then
        local Character = plr.Character
        local Player = game.Players:GetPlayerFromCharacter(Character)
        local AlreadyInTable = false
        for _,OtherPlayer in pairs (PlayersToTeleport) do
            if OtherPlayer == Player then
                AlreadyInTable = true
            end
        end
        if not AlreadyInTable then
        table.insert(PlayersToTeleport,Player)
        end
    end
end)
0
Yes, it is now fixed darieus887 -3 — 4y
Ad

Answer this question