Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I check if a value is greater than or equal to?

Asked by
2_MMZ 1059 Moderation Voter
3 years ago
Edited 3 years ago

Hey! I'm currently in the process of making a tycoon game. When the player buys the seating, for 5$, it will take away value (which is something I don't know how to do yet). There's an IntValue inside of the money text.

ProximityPrompt:

1local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("TakeCashSeating")
2 
3script.Parent.Triggered:Connect(function(player)
4       remEvent:FireClient(player)
5end)

LocalScript in StarterGUI:

01local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("TakeCashSeating")
02 
03remEvent.OnClientEvent:Connect(function()
04    if script.Parent.ScreenGui.changecolor.currency.money.Value >= 5 then
05    script.Parent.ScreenGui.changecolor.currency.money.Value = 0
06    script.Parent.ScreenGui.changecolor.currency.money.Text = s cript.Parent.ScreenGui.changecolor.currency.money.Value
07    else
08        script.Parent.ScreenGui.changecolor.currency.errornote.Visible = true
09        script.Parent.error:Play()
10        wait(1.1)
11        script.Parent.ScreenGui.changecolor.currency.errornote.Visible = false
12    end
13end)

Any working answer is appreciated.

1 answer

Log in to vote
1
Answered by
jundell 106
3 years ago
Edited 3 years ago

The greater than or equal to sign is >=, which I see you are already using in your script. I recommend you take a look at this page if you simply want to know operators, although they don’t seem to be your problem. You are trying to set .Text and .Value of an instance, and you aren’t removing the $5, just setting the value to zero. This code below assumes that the IntValue is named IntValue and is parented to script.Parent.ScreenGui.changecolor.currency.money.

01local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("TakeCashSeating")
02local currency = script.Parent.ScreenGui.changecolor.currency
03 
04remEvent.OnClientEvent:Connect(function()
05    if currency.money.IntValue.Value >= 5 then -- has enough money
06        currency.money.IntValue.Value = currency.money.IntValue.Value - 5 --take away 5 from money
07        currency.money.Text = currency.money.IntValue.Value --set text
08    else --not enough money
09        currency.errornote.Visible = true
10        script.Parent.error:Play()
11        wait(1.1)
12        currency.errornote.Visible = false
13    end
14end)
Ad

Answer this question