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

BoolValue printing false despite being true?

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)

1 comment

0

The mistake is in the relationship between client and server

1 answer

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?

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