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
2 years ago
Edited 2 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:

local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("TakeCashSeating")

script.Parent.Triggered:Connect(function(player)
       remEvent:FireClient(player)
end)

LocalScript in StarterGUI:

local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("TakeCashSeating")

remEvent.OnClientEvent:Connect(function()
    if script.Parent.ScreenGui.changecolor.currency.money.Value >= 5 then
    script.Parent.ScreenGui.changecolor.currency.money.Value = 0
    script.Parent.ScreenGui.changecolor.currency.money.Text = s cript.Parent.ScreenGui.changecolor.currency.money.Value 
    else
        script.Parent.ScreenGui.changecolor.currency.errornote.Visible = true
        script.Parent.error:Play()
        wait(1.1)
        script.Parent.ScreenGui.changecolor.currency.errornote.Visible = false
    end
end)

Any working answer is appreciated.

1 answer

Log in to vote
1
Answered by
jundell 106
2 years ago
Edited 2 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.

local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("TakeCashSeating")
local currency = script.Parent.ScreenGui.changecolor.currency

remEvent.OnClientEvent:Connect(function()
    if currency.money.IntValue.Value >= 5 then -- has enough money
        currency.money.IntValue.Value = currency.money.IntValue.Value - 5 --take away 5 from money
        currency.money.Text = currency.money.IntValue.Value --set text
    else --not enough money
        currency.errornote.Visible = true
        script.Parent.error:Play()
        wait(1.1)
        currency.errornote.Visible = false
    end
end)
Ad

Answer this question