Attempt to compare number <= nil

Hello there,
im making a flip system.

How does it work?
U basically input a number and then u press flip. You have a 50/50 chance of winning.
If you win u get double amount and if u lose u lose the amount.

When making and testing, i got this error: Attempt to compare nil <= number Line 87 ServerScriptService: Script

This is my Code:

----------------------------------------------------------------------------------- FLIP GAME
game.ReplicatedStorage.GameEvents.FlipEvent.OnServerEvent:Connect(function(player)
   local num = tonumber(player.PlayerGui.MainUI.FlipGame.DecorationI.TextBox)
	if player.leaderstats.MetaBucks.Value >=num then

			local Trigger = script.Parent -- The Trigger
			-- localFUNCTION
			-- Function
			 -- when Triggered function
				player.leaderstats.MetaBucks.Value = player.leaderstats.MetaBucks.Value -num
		local Chance = math.random(1,100)
		local function win()
			player.leaderstats.MetaBucks.Value = num *2
			player.PlayerGui.MainUI.FlipGame.DecorationI.wintxt.TextColor3 = Color3.fromRGB(92, 163, 255)
			wait(1)
			player.PlayerGui.MainUI.FlipGame.DecorationI.wintxt.TextColor3 = Color3.fromRGB(43, 47, 72)
			player.PlayerGui.MainUI.FlipGame.DecorationI.Status.Text = ("You won and you got "..num *2 .."!")
			wait(2)
			player.PlayerGui.MainUI.FlipGame.DecorationI.Status.Text = ("Press FLIP to flip")
		end

		local function lose()
			player.PlayerGui.MainUI.FlipGame.DecorationI.l.TextColor3 = Color3.fromRGB(92, 163, 255)
			wait(1)
			player.PlayerGui.MainUI.FlipGame.DecorationI.l.TextColor3 = Color3.fromRGB(43, 47, 72)
			player.PlayerGui.MainUI.FlipGame.DecorationI.Status.Text = ("You sadly lost, try again!")
			wait(2)
			player.PlayerGui.MainUI.FlipGame.DecorationI.Status.Text = ("Press FLIP to flip")
		end
				if Chance <= 55 then -- if the answer is 55 or under you will lose
			lose()
		
		elseif Chance  <= 50 then -- if the answer is 55 or under you will win
			win()
			
				end	
	end
end)
----------------------------------------------------------------------------------------------------

I would really appreciate it when you could help!
Thank you and have a nice day!

I also tried adding .Text but it wont work.

I still get the error

local num = tonumber(player.PlayerGui.MainUI.FlipGame.DecorationI.TextBox)

Text input into textboxes by the client cannot be read from the server (as the text does not replicate to the server), you need to use a network object (i.e; a RemoteEvent) in order to transfer the text to the server.

You forgot to add .Text after DecorationI.TextBox

1 Like

That line of code was copied and pasted from the provided script, I didn’t make any changes to it. Regardless of whether or not .Text was indexed, the server cannot read the contents of textboxes produced by the client.

1 Like

So how do i fix this error, i also meant to say attempt to compare number to nil.
How do i fix now?

You need to use a RemoteEvent/RemoteFunction object in order to send the textbox’s text from the client to the server.

1 Like

How do you do that? Sorry im not the master of scripting.
If u meant like remote event in repStorage, i have, look at the line 1, the RemoteEvent is FlipEvent

I can show you a picture of the destinations here:
ok

To send data to server then use RemoteEvent:FireServer(data_here) in the local script.

Now in server script do

RemoteEvent.onServerEvent:Connect(function(data)
    print(data)
end)

nil print
I got this, it prints nil. How do i apply that number to the text? Should i do while true or for loop idk im confused

I forgot to include player in the .onServerEvent

RemoteEvent.onServerEvent:Connect(function(player,data)
    print(data)
end)

Here

Right now your only getting the instance (Textbox) Not the property.
Code:

local num = tonumber(player.PlayerGui.MainUI.FlipGame.DecorationI.TextBox.Text)

Its the same with the “.Text” its not working

The .Text is converting the text in the textbox to a number and returning it