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

Script not recognizing the text in a text label?

I have this script and it does something once both statements are true, i think the problem is on line 5, I don't see anything wrong though, I get no errors. Edit: You need click "view source" to see the whole code, sorry.

game.Players.PlayerAdded:Connect(function(plr)
plr.PlayerGui:WaitForChild("Game"):WaitForChild("Frame"):WaitForChild("Night"):WaitForChild("PlayersReady").Changed:Connect(function()
	local ign = game.ReplicatedStorage.InGameNames:GetChildren()

	if plr.PlayerGui:WaitForChild("Game"):WaitForChild("Frame"):WaitForChild("Night"):WaitForChild("PlayersReady").Text == #ign then
		game.ReplicatedStorage.Values.DayNight.Value = true
	end
end)
end)

4 comments

0

Use the Changed event on the TextBox, that should fix it.

0

I did, "PlayersReady" is a text label

0

For detect Text and things like this, you need to use a LocalScript because the server can't see the changes of the client. and a LocalScript can, for do this that you are trying to do, try to use a RemoteEvent

0

^ More specifically, if the server did not assign a child of the PlayerGui to the PlayerGui, it cannot see that child. Any child that cannot be viewed by the server can be viewed by the client, via a LocalScript.

2 answers

im not sure if its right but line 5 should be...

 if plr.PlayerGui:WaitForChild("Game"):WaitForChild("Frame"):WaitForChild("Night"):WaitForChild("PlayersReady").Text == tostring(#ign) then

1 comment

0

Yep, this is right. You can't compare a string to a number.

@NSMascot that doesn't work overall though, I changed the script a bit and it doesn't print success once

game.Players.PlayerAdded:Connect(function(plr)
plr:WaitForChild("PlayerGui"):WaitForChild("Game"):WaitForChild("Frame"):WaitForChild("Night"):WaitForChild("PlayersReady").Changed:Connect(function()
	local ign = game.ReplicatedStorage.InGameNames:GetChildren()

if #ign > 0 then 
	print("Success!")
	if plr:WaitForChild("PlayerGui"):WaitForChild("Game"):WaitForChild("Frame"):WaitForChild("Night"):WaitForChild("PlayersReady").Text == tostring(#ign) then
		print("Success!")
			game.ReplicatedStorage.RemoteEvents.DayNightCycle:FireServer()
		end
	end
end)
end)


Thanks though!

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