Damn near impossible fix

Yo guys, im working on a sort slot machine thing system (dont ask) and it gives me a error no one on the planet has ever seen:

00:04:02.414 ServerScriptService.CasinoHandlerThing:42: attempt to compare number < nil - Server - CasinoHandlerThing:42

so yeah line 42?

this is line 42:

if not money or money.Value < placedBet then
			outCome.Text = "Not enough money to place the bet!"
			print("Not enough money!")
			return
		end

this is the money far back the script:

local money = game.ReplicatedStorage:WaitForChild("Money")

like i dont see the problem.

Every help is appreciatted thanks.

1 Like

money or placedBet might be nil, place a print script before: print(money, placedBet) to debug it.

2 Likes

How would that work like, isnt this good?
local placedBet = tonumber(Catrino.PlrInput.Text)

tonumber can still return nil if the text isnt a number

3 Likes

but the txt in the thing is a number
here is a quick vid: https://gyazo.com/86d6ea3d24d45fb8248b6cda32c7120a

placedBet is nil; gauging other replies you need to add another error to check for

if placedBet == nil then
    outCome.Text = "Invalid input, not a number!"
    return
end

if not money or money.Value < placedBet then
	outCome.Text = "Not enough money to place the bet!"
	print("Not enough money!")
	return
end
2 Likes

that would work @emiliotigre2017

Found kinda where it comes from
Added: print("Input Text:", Catrino.PlrInput.Text)

printed:

00:14:01.907 Input Text: - Server - CasinoHandlerThing:31
00:14:01.907 Invalid bet amount! - Server - CasinoHandlerThing:36

basicaly not printing anything meaning its not detecting anything

Can you show how you define the variable Catrino? Maybe you are using StarterGUI when you need PlayerGUI?

Im using plrgui

local Catrino = playerGui.MainScreen.FrameCasino
	local outCome = Catrino.WonORlose
	local button = Catrino.PlaceBet
	local slots = {Catrino.SlotPlace1, Catrino.SlotPlace2, Catrino.SlotPlace3}
	local placedBet = tonumber(Catrino.PlrInput.Text)

and i have:

print("Input Text:", Catrino.PlrInput.Text)

		
		if not placedBet or placedBet <= 0 then
			outCome.Text = "Invalid bet amount!"
			print("Invalid bet amount!")
			return
		end

as checks

1 Like

I think this proves that player’s text fields are not replicated and must be sent through a remote event. You will have to split this input field into a Local script

1 Like

How would that look like? Im kinda empty rn, kinda lost

Where & when are you defining placedBet?

Is this before or after the player actually enters text? Does it ever change?

If it’s before the player enters text and is never re-assigned, it will always be whatever the Text value was upon loading the game.

Also, are you using a ServerScript instead of Local?:

I actually managed to fix stuff, im coming back later on ur statement

1 Like

Create a remote event in ReplicatedStorage, lets name it PlaceBet

Create a local script as a child of your bet text input.

local place_bet_remote = game:GetService("ReplicatedStorage").PlaceBet
script.Parent.FocusLost:Connect(function(enter_pressed)
    if enter_pressed then
        place_bet_remote:FireServer(script.Parent.Text)
    end
end)

For your server script you now have to run your function as part of the remote event

local place_bet_remote = game:GetService("ReplicatedStorage").PlaceBet

place_bet_remote.OnClientEvent:Connect(function(player, bet_text)
    local Catrino = player.PlayerGui.MainScreen.FrameCasino
    local placedBet = tonumber(bet_text)

   -- etc..
end)

Here’s more on remote events on roblox

I know how remote events work, and the script works now, im still testing

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.