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

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)

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)

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)

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