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

Button wont work after clicking two times in a row, pls help?

Asked by 2 years ago

So I have a button that gives the user a gun than destroys the one they have in there inventory but if you click the button again within a few seconds the gun will be destroyed and nothing will be in its place. I tried adding a wait but that did nothing, here is the code

local button = script.Parent
local plr = game:GetService('Players').LocalPlayer

local tool = game.ReplicatedStorage.ACS_Engine.HOOD["Micro UZI"] 

button.Activated:Connect(function()
    script.Parent.Parent.Visible = false
    plr.Backpack:FindFirstChildWhichIsA('Tool'):Destroy()
    local clone = tool
    clone.Parent = plr.Backpack
    wait(0.5)
    script.Parent.Parent.Parent.ClassH.Visible = true
    wait(3)
    script.Parent.Parent.Parent.ClassH.Visible = false
end)

Thanks!

2 answers

Log in to vote
0
Answered by
vileras 22
2 years ago

Try This:

local button = script.Parent
local plr = game:GetService('Players').LocalPlayer
local tool = game.ReplicatedStorage.ACS_Engine.HOOD["Micro UZI"]:Clone()

button.Activated:Connect(function()
script.Parent.Parent.Visible = false
plr.Backpack:FindFirstChildWhichIsA('Tool'):Destroy()
tool.Parent = plr.Backpack
 wait(0.5)
script.Parent.Parent.Parent.ClassH.Visible = true
wait(3)
script.Parent.Parent.Parent.ClassH.Visible = false
end)

0
He's trying to clone the tool. This did not help... tightanfall 110 — 2y
0
thanks for the answer vileras look at the comments that I put on tightanfalls answer(Im to lazy to write them again) Iownrobloxp 44 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
local button = script.Parent
local plr = game:GetService('Players').LocalPlayer
local tool = game.ReplicatedStorage.ACS_Engine.HOOD['Micro UZI']
local cooldown = false --//r

button.Activated:Connect(function()
    if cooldown == false then --//r
        cooldown = true --//r
        script.Parent.Parent.Visible = false
        plr.Backpack:FindFirstChildWhichIsA('Tool'):Destroy()
        local clone = tool:Clone() --// You forgot the :Clone()
        clone.Parent = plr.Backpack
        wait(0.5)
        script.Parent.Parent.Parent.ClassH.Visible = true
        wait(3)
        script.Parent.Parent.Parent.ClassH.Visible = false
        cooldown = false --//r
    end --//r
end)

You forgot to actually clone the tool. You were just grabbing the tool from replicated storage and placing it into the players backpack without making a copy.

I also added a cooldown, if you dont want it just remove the things labeled --//r

0
thank you so much for your answer but there is one problem if I clone the tool(gun) the tool wont work. so instead I actually did mean to grab it from replicated storage, I just put alot of them into a folder(30,50). maybe there could be a way to disable the button after you use it? and then re-enable it once you die? Iownrobloxp 44 — 2y
0
I just found out that the button wouldn't work even if you clicked it again after 3 sec it would just destroy the tool that you had and not clone it(leaving you with nothing) and then if you tried clicking it after that Nothing would happen, you would need to reset than it would work again Iownrobloxp 44 — 2y

Answer this question