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

Help with buy button?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago

So I have a working buying button but the player is able to get the button after 10 seconds if they got one already. So they can keep getting if they have enough money(which I don't want them to get more than 1). Once they have one, want to prevent them from getting another. I HAVE NO CLUE ON HOW TO DO THIS! Thanks for the help, please explain a little.

d = true

script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:WaitForChild("Humanoid")
    local tool = game.ServerStorage:WaitForChild("GravityCoil")
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local stats = plr:WaitForChild("leaderstats").Tags

    if d then
        if stats.Value >= 50 then
            d = false
            if hum then
                tool:Clone().Parent = plr.Backpack
                stats.Value = stats.Value - 10
            end
            wait(10)
            if plr.Backpack.Tool then
                --code?
            end
            d = true
        end
    end
end)

2 answers

Log in to vote
1
Answered by 7 years ago

What you'll need to figure out if it is there or not.

First of all, you'll need to have the name of it, not just Tool. Instead of plr.Backpack.Toolyou should use plr.Backpack.GravityCoil Or for efficiency, do this: plr.Backpack:FindFirstChild(tool.Name)

Now you shall have to do the code. This is really easy, you don't even have to do it! Delete that line and for the above line, do this:

if plr.Backpack:FindFirstChild(tool.Name) then return end

Finished Script

d = true

script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:WaitForChild("Humanoid")
    local tool = game.ServerStorage:WaitForChild("GravityCoil")
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local stats = plr:WaitForChild("leaderstats").Tags

    if d then
        if stats.Value >= 50 then
            d = false
            if hum then
                tool:Clone().Parent = plr.Backpack
        tool:Clone().Parent = plr.StarterGear
                stats.Value = stats.Value - 10
            end
            wait(10)
            if plr.Backpack:FindFirstChild(tool.Name) then return end
            d = true
        end
    end
end)

One more thing. You should probably clone it into StarterGear so they will get it when they respawn. I did that in the above code.

Hope this helped!

Ad
Log in to vote
0
Answered by 7 years ago

Solution:

Using the not boolean in the if statements would help a lot!

Here is your script and it's simple to make sure the person doesn't get an extra one after he already has one.... I think the name of the Tool for you is Tool however you may change the name and when you do I am going to be putting a variable for the Tool Name so you can just change it when you change the name!

Here is the script:

d = true

script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:WaitForChild("Humanoid")
    local tool = game.ServerStorage:WaitForChild("GravityCoil")
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local stats = plr:WaitForChild("leaderstats").Tags
    local toolname = "Tool" -- If that is the tool name.
    local backpack = plr:WaitForChild("Backpack") -- Variable for backpack
    local toolcheck = backpack:findFirstChild(toolname) -- Variable for checking if      
    the tool exists with the :findFirstChild() method.


    if d and stats.Value >= 50 then
            d = false
            if hum and not toolcheck then
                tool:Clone().Parent = backpack
                stats.Value = stats.Value - 10
            end
            wait(10)
            if toolcheck then
                --code?
            end
            end
            d = true
    end
end)

Anyways the above script should work. If it does not please post in the comment what the error was. If there is no error then invite me to team create and I can check it out.

To learn more about not booleans go here:

http://wiki.roblox.com/index.php?title=Boolean

To learn more aboutConditional Statements go here:

http://wiki.roblox.com/index.php?title=Conditional_statement

I hope I helped and thank you for using your precious time to read this answer!

~~ KingLoneCat

0
Did you miss some code? FiredDusk 1466 — 7y
0
I don't think so. Why any problems? KingLoneCat 2642 — 7y

Answer this question