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
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

Log in to vote
0
Answered by 4 years ago

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)
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

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)

Answer this question