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

Why won't this check if a number is greater than one and a number?

I have made a script in which I want it to check whether when a TextBox changes it checks whether what has been entered so far is a number and is greater than one, if not, it will say to enter the number again until clicked enter (Which I still need to add). However, whenever I change the TextBox in the game it doesn't print anything or do anything and I'm not sure why.

Code:

local racesCountText = game.StarterGui.racesCount.TextBox

racesCountText:GetPropertyChangedSignal("Text"):Connect(function()
	if tonumber(racesCountText.Text) then
		if racesCountText > 1 then
			racesCount = racesCountText.Text
			print("This is a valud number")
		else
			racesCountText.Parent.TextLabel.Text = "Please try and enter the number again, it has to be greater than one."
		end
	else
		racesCountText.Parent.TextLabel.Text = "Please try and enter the number again, this isn't a valid nuber."
	end
end)

1 answer

✓ Accepted answer

Your event fires when racesCountText fires. However, you set racesCountText = game.StarterGui.racesCount.TextBox. This mean it's waiting for the gui inside of StarterGui to change. When a player enters the game, the guis inside of StarterGui are cloned into their PlayerGui, so when you change the gui in StarterGui the players don't see those effects. What you could do is put all this code into a LocalScript and put that inside of the TextBox, because Guis are best handled on the client. If you need to later do anything more important you can use a remoteEvent to handle the rest on the server.

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