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

how do i stop a touched statement from running multiple times?

Asked by 3 years ago
game.Players.PlayerAdded:Connect(function(plr)
    game.Workspace.too.Touched:Connect(function(hit)
        local fld = Instance.new("Folder")
        fld.Parent = plr.StarterGear
        local st = plr:FindFirstChild("StringValue")

        if not st then
            local newSt = Instance.new("StringValue")
            newSt.Name = newSt.ClassName
            newSt.Parent = plr.StarterGear.Folder
        end
    end)
end)


0
local wasTouched=false; right after the Connect function put if wasTouched==false then and put wasTouched= true and put "end" right before the end of the .Touched function Brycefitz2008 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Make a debounce.

local Debounce = true

game.Players.PlayerAdded:Connect(function(plr)
    game.Workspace.too.Touched:Connect(function(hit)
        if Debounce then
            Debounce = not Debounce
            local fld = Instance.new("Folder")
                fld.Parent = plr.StarterGear
                local st = plr:FindFirstChild("StringValue")

                if not st then
                        local newSt = Instance.new("StringValue")
                        newSt.Name = newSt.ClassName
                        newSt.Parent = plr.StarterGear.Folder
                end
        end
    end)
end)

0
Yep! This works, and then if you want it to run after a couple seconds add wait(2) Debounce = true at the end. JailBreaker_13 350 — 3y
Ad

Answer this question