Why does this script now work?

while wait(3) do
local plr = game:GetService("Players")
	for i, v in pairs(plr:GetChildren())	 do
		local plrgui = v:FindFirstChild("PlayerGui")
		local screen = plrgui:FindFirstChild("ScreenGui")
		local button = screen:FindFirstChild("TextButton")
		if button.Text == "RACE:OFF" then return end
		if button.Text == "RACE: ON" then
			print("Run was on")
			local plrname = v.Name
			local plrchar = workspace:FindFirstChild(plrname)
			local hrp = plrchar:FindFirstChild("HumanoidRootPart")
			local tppart = workspace.Tppart
			hrp.Position = tppart.Position
		else 
			warn("Error")
		end
	end
end

Local:

local buton = script.Parent
script.Parent.Activated:Connect(function()
	if script.Parent.Text == "RACE: ON" then
		script.Parent.Text = "RACE:OFF"
	else
		script.Parent.Text = "RACE: ON"
	end
end)

It just keeps teleporting me even if the button says “RACE:OFF”

Last time I checked PlayerGuis do not replicate to the server? You can’t read the properties of the GUI of individual players and doing so will just give you their initial state

To confirm this, try printing out the text of the button in the server script and see if it’s actually off

3 Likes

I see, what can I do to fix this?

You can use a remote instead. Whenever the player toggles the button, send a remote to the server telling it their status, which can be stored in a table. From there, when the round starts the server can easily check who’s playing and who’s not by using the table

1 Like

1.You should use task.wait instead of wait.
2.You should use GetPlayers instead of GetChildren [this would ensure you to get only players].
3.You can’t access other players’ GUI’s from the client.

Try to send a Remote Event to the server, and from there - modiy/edit stuff to your likings.

1 Like