because when i press spin... i should have the money to buy the crate.... but if i don't how do i not activate the crate.... because i have no money... still i can spin and get items from the crate... nothings wrong with the script, but how do i put the code in the script?
Here's the code: local list = {
}
local Enabled = true
script.Parent.MouseButton1Click:Connect(function() if Enabled == false then return end Enabled = false
01 | local time = 0.025 |
02 |
03 | for i = 1 , 75 do |
04 | script.Parent.Parent.result.Text = list [ math.random( 1 , #list) ] |
05 |
06 | if i = = 50 then time = 0.05 end |
07 | if i = = 55 then time = 0.1 end |
08 | if i = = 60 then time = 0.2 end |
09 | if i = = 65 then time = 0.4 end |
10 | if i = = 70 then time = 0.8 end |
11 | if i = = 75 then |
12 | script.Parent.Parent.text.Text = "You have aquired..." |
13 | script.Parent.Parent.done.start.Disabled = false |
14 | end |
15 | wait(time) |
16 | end |
end)
Just check it's money and see if it is higher or equal to the price. Here's a simle example.
Let's say your money is in a leaderboard:
THIS MUST BE A LOCAL SCRIPT (Since you're working with a crate opening system)
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | local money = game.Players.LocalPlayer:WaitForChild( "leaderstats" ).Money.Value --Check the player's money |
03 | if money > = CRATE PRICE HERE then --If player's money is higher or equal to the crate price: |
04 |
05 |
06 | --//Run the open crate code\\-- |
07 |
08 |
09 | end |
10 | end ) |
if you're not using a leaderstats, just point out the script where the money value is.
Also, pro tip when using if to check if a value is false instead of using if something.something.Value == false then
, instead use if not something.something.Value then
. It's more pratical. If not means if the valus is false then. And without a not it's if it's true.
Keep on coding!
Edit: If you want to make something else to happen if player doesn't have money just use an "else". Here's the script with it:
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | local money = game.Players.LocalPlayer:WaitForChild( "leaderstats" ).Money.Value --Check the player's money |
03 | if money > = CRATE PRICE HERE then --If player's money is higher or equal to the crate price then.. |
04 |
05 |
06 | --//Run the open crate code\\-- |
07 |
08 | else --else means the opposite, so in this case if the player doesn't have money do.. |
09 |
10 | --//Run the code that informs the player they don't have enough money (or whatever you want to do)\\-- |
11 |
12 | end |
13 | end ) |