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

How to use debounce correctly?

Asked by 10 years ago

I'm pretty sure my problem is debounce not being used correctly. The despawn part doesn't work and despawns the part for like 1 second. If someone could fix this that'd be great thanks.

debounce = false
script.Parent.Text = "Spawn Pet"
script.Parent.MouseButton1Down:connect(function()
    if debounce == true then return end
        debounce = true
 local plr = script.Parent.Parent.Parent.Parent.Character
 owner = script.Parent.Parent.Parent.Parent.Name
 part = Instance.new("Part", Workspace)
 part.Anchored = true
 while wait(0.1) do
  part.CFrame = CFrame.new(plr.Torso.Position + Vector3.new(5,-2.4,5))
    script.Parent.Text = "Despawn Pet"
    part.Name = (owner.."'s Pet")
    script.Parent.MouseButton1Down:connect(function()
        part:Destroy()
        debounce = false
        end)
 end
end)
0
Within your while loop, you destroy the part, which is the original part. I suggest cloning it or creating a new part using Instance because this script will just name the part and destroy it.. Shawnyg 4330 — 10y
0
It should name the part then when you click it again it destroys the part. GetSporked 5 — 10y
0
I see what you meant shawnyg. GetSporked 5 — 10y
0
Mk, great. Tell me if you need additional help. Shawnyg 4330 — 10y
View all comments (2 more)
0
I actually do, I have this much so far it spawns the brick then you can despawn it and thats it... http://prntscr.com/42n7f5 GetSporked 5 — 10y
0
Nevermind it GetSporked 5 — 10y

Answer this question