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

when i press buy how do i disable it if the money of the player does not meet the price?

Asked by 6 years ago

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

01local time = 0.025
02 
03for i = 1, 75 do
04    script.Parent.Parent.result.Text = list[math.random(1,   #list)]
05 
06    if == 50 then time = 0.05 end
07    if == 55 then time = 0.1 end
08    if == 60 then time = 0.2 end
09    if == 65 then time = 0.4 end
10    if == 70 then time = 0.8 end
11    if == 75 then
12           script.Parent.Parent.text.Text = "You have aquired..."
13           script.Parent.Parent.done.start.Disabled = false
14    end
15    wait(time) 
16end

end)

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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)

01script.Parent.MouseButton1Click:Connect(function()
02local money = game.Players.LocalPlayer:WaitForChild("leaderstats").Money.Value --Check the player's money
03if 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 
09end
10end)

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:

01script.Parent.MouseButton1Click:Connect(function()
02local money = game.Players.LocalPlayer:WaitForChild("leaderstats").Money.Value --Check the player's money
03if 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 
08else --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 
12end
13end)
0
here's the thing i put it in a dialog shop,then the gui appears, then spin button is there. if i press it, if i have the money or not to but the crate, it still spins. how do i put that in the script? doomoxima21 17 — 6y
0
thank you! plz add me so i can give u something in the game in the future doomoxima21 17 — 6y
0
Alrighty, adding you. Feel free to contact me if you need any more help. wilsonsilva007 373 — 6y
0
Edited the Answer to your question. Check it out. wilsonsilva007 373 — 6y
Ad

Answer this question