So I am developing a Roblox game that relies on purchasing cosmetics and other items. To get the currency for these items, there's classes in the game that you can attend and play mini games to get money. The starter amount of money you have when you first join the game is $50. So scripting the actual getting the money is good, it's purchasing items that I need help with.
I'm using the same script we used for getting money, except instead of having "+(number of currency) at the bottom, we replaced the + with a - to decrease the value. But because the starting value is 50, you can still purchase it for 1,000, it will just decrease your money to -950. But I don't want that happen. I want to make it so if you try to purchase it but you don't have enough money for it, it won't purchase and your money won't decrease. I tried scripting this myself but I don't have the best knowledge of how scripts in Roblox work. I added "if Coins.Value = 1000 then" above the actual part of the script that decreases money, as an attempt to make it so it will only decrease if the amount of money you have in 1,000.
Additional Info: This script is for a GUI Button. The purchasing happens when you click on the button. This script is a script in ServerScriptService and "RS" is the variable for Replicated Storage.
Here's the script:
game.Players.PlayerAdded:Connect(function(Player)
local Data = Instance.new("Folder", Player)
Data.Name = "Data"
local Coins = Instance.new("IntValue", Data)
Coins.Name = "Dust"
Coins.Value = 50
end)
if Coins.Value = 1000 then
local RS = game:GetService("ReplicatedStorage")
local Remote = RS.LockerPurchase
Remote.OnServerEvent:Connect(function(Player)
Player.Data.Dust.Value = Player.Data.Dust.Value - 1000
wait(0.1)
end
end)
If you have any ideas that could help, please let me know! <3

1 comment
This worked! Thank you all so much!!