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
local time = 0.025 for i = 1, 75 do script.Parent.Parent.result.Text = list[math.random(1, #list)] if i == 50 then time = 0.05 end if i == 55 then time = 0.1 end if i == 60 then time = 0.2 end if i == 65 then time = 0.4 end if i == 70 then time = 0.8 end if i == 75 then script.Parent.Parent.text.Text = "You have aquired..." script.Parent.Parent.done.start.Disabled = false end wait(time) 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)
script.Parent.MouseButton1Click:Connect(function() local money = game.Players.LocalPlayer:WaitForChild("leaderstats").Money.Value --Check the player's money if money >= CRATE PRICE HERE then --If player's money is higher or equal to the crate price: --//Run the open crate code\\-- end 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:
script.Parent.MouseButton1Click:Connect(function() local money = game.Players.LocalPlayer:WaitForChild("leaderstats").Money.Value --Check the player's money if money >= CRATE PRICE HERE then --If player's money is higher or equal to the crate price then.. --//Run the open crate code\\-- else --else means the opposite, so in this case if the player doesn't have money do.. --//Run the code that informs the player they don't have enough money (or whatever you want to do)\\-- end end)