Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

2 comments

0

And you fire the MoveBus event?

0

Use print()'s to determine where the function is running and where it is not running. It will help you out a ton.

1 answer

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)

1 comment

0

Yes, it is now fixed

This discussion is preserved as it was. New answers, comments, and votes are closed.