Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I've got a problem with debounce script, any help?

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local debounce = false
	
	if plr then
		plr.Character.HumanoidRootPart.CFrame = CFrame.new(-81.2, 26, -10.6)
			if not debounce then
             debounce = true
			 plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10
			 wait(15)
             debounce = false
     end
	end
	end)

I've made a debounce script to stop giving player points when it touched the part. (example, I want to give player 10 points, but It gives me 40)

any help is appreciated :]

2 answers

✓ Accepted answer

You should put the debounce variable outside

local debounce = false
script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then -- You can do this as well
		plr.Character.HumanoidRootPart.CFrame = CFrame.new(-81.2, 26, -10.6)
		if not debounce then
			debounce = true
			plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10
			wait(15)
			debounce = false
		end
	end
end)

script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local debounce = false

if plr then
    plr.Character.HumanoidRootPart.CFrame = CFrame.new(-81.2, 26, -10.6)
        if (debounce == false) then
         debounce = true
	if(hit.Parent.Name == "Your Name")then
         plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 40
else
	plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10
         wait(15)
         debounce = false

end end end end)

This discussion is preserved as it was. New answers, comments, and votes are closed.