Hello, i have a bool value in players that turn true when they press the GUI. Except when the function fires despite the bool value being true to prints false and acts false. Thank you.
Trouble code:
local function setPosition(player) wait(5) local toJoin = player:FindFirstChild("toJoin") if toJoin.Value then print("true") else if toJoin.Value == false then print("False") end end end startRace.Changed:Connect(function(value) if value then for _, player in pairs(game.Players:GetChildren()) do setPosition(player) end end
Full Code:
local replicatedStorage = game:GetService("ReplicatedStorage") local startRace = replicatedStorage.StartRace game.Players.PlayerAdded:Connect(function(player) local inRace = Instance.new("BoolValue", player) inRace.Value = false inRace.Name = "inRace" local toJoin = Instance.new("BoolValue", player) toJoin.Value = false toJoin.Name = "toJoin" end) local function setPosition(player) wait(5) local toJoin = player:FindFirstChild("toJoin") if toJoin.Value then print("true") else if toJoin.Value == false then print("False") end end end startRace.Changed:Connect(function(value) if value then for _, player in pairs(game.Players:GetChildren()) do setPosition(player) end end end) wait(10) startRace.Value = true
Gui Changer Code:
local player = game.Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") local toJoin = screenGui.ToJoin.ToJoinButton toJoin.MouseButton1Click:Connect(function() local toJoin = player:FindFirstChild("toJoin") if toJoin.Value then toJoin.Value = false else toJoin.Value = true end end)
Well, before answering this question, is the gui changer code in a local script or a server script? You cannot change a server value with a local script. You could try firing a remote event to change it on a server script?