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

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

Asked by 4 years ago
01script.Parent.Touched:Connect(function(hit)
02    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
03    local debounce = false
04 
05    if plr then
06        plr.Character.HumanoidRootPart.CFrame = CFrame.new(-81.2, 26, -10.6)
07            if not debounce then
08             debounce = true
09             plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10
10             wait(15)
11             debounce = false
12     end
13    end
14    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

Log in to vote
0
Answered by 4 years ago

You should put the debounce variable outside

01local debounce = false
02script.Parent.Touched:Connect(function(hit)
03    if game.Players:GetPlayerFromCharacter(hit.Parent) then -- You can do this as well
04        plr.Character.HumanoidRootPart.CFrame = CFrame.new(-81.2, 26, -10.6)
05        if not debounce then
06            debounce = true
07            plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10
08            wait(15)
09            debounce = false
10        end
11    end
12end)
Ad
Log in to vote
0
Answered by 4 years ago

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

01if plr then
02    plr.Character.HumanoidRootPart.CFrame = CFrame.new(-81.2, 26, -10.6)
03        if (debounce == false) then
04         debounce = true
05    if(hit.Parent.Name == "Your Name")then
06         plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 40
07else
08    plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10
09         wait(15)
10         debounce = false

end end end end)

Answer this question