CurrentPrice = script.Parent.Worth Debounce = true PickedUp = false script.Parent.Touched:Connect(function(hit) if Debounce and hit.Parent.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == "Trashpick" and not PickedUp then print("Trash is now PickedUp") Debounce = false script.Parent.Transparency = 1 local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) player:FindFirstChild("leaderstats") player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + CurrentPrice.Value print("Player picked up trash") PickedUp = true wait(10) PickedUp = false script.Parent.Transparency = 0 end end)
Here is my script, It works fine BUT it does not work MULTIPLE times. I would want to after the Transparency is set to = 0 I want the script to be working again, please help!
I think you forgot to set the debounce to true again? I mean, line 09 sets the debounce to false and no other lines seem to put it back to true?
Try this I guess.
CurrentPrice = script.Parent.Worth Debounce = true PickedUp = false script.Parent.Touched:Connect(function(hit) if Debounce and hit.Parent.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == "Trashpick" and not PickedUp then print("Trash is now PickedUp") Debounce = false script.Parent.Transparency = 1 local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) player:FindFirstChild("leaderstats") player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + CurrentPrice.Value print("Player picked up trash") PickedUp = true wait(10) PickedUp = false Debounce = true -- Resets variable Debounce back to true script.Parent.Transparency = 0 end end)
Just a little mistake if I am right.