I want the leader stats value to only change once, not every time a different body part touches another part. I have tried disabling being able to walk and jump after touching the part but that still didn’t work.
Stage1Check.Touched:Connect(function(hit)
local humanoid= hit.Parent:FindFirstChild("Humanoid")
if humanoid ~=nil then
humanoid.WalkSpeed = 0
humanoid.JumpHeight = 0
player.leaderstats["Stage 1 Completes"].Value = player.leaderstats["Stage 1 Completes"].Value + 1
print("I am being Touched")
end -- then statement end
end)
You can store the event in a variable and then use :Disconnect() on it
local event =Stage1Check.Touched:Connect(function(hit)
local humanoid= hit.Parent:FindFirstChild("Humanoid")
if humanoid ~=nil then
player.leaderstats["Stage 1 Completes"].Value = player.leaderstats["Stage 1 Completes"].Value + 1
print("I am being Touched")
event:Disconnect()
end -- then statement
end)
local debounce = false
Stage1Check.Touched:Connect(function(hit)
if not debounce then
debounce = true
local humanoid= hit.Parent:FindFirstChild("Humanoid")
if humanoid ~=nil then
humanoid.WalkSpeed = 0
humanoid.JumpHeight = 0
player.leaderstats["Stage 1 Completes"].Value = player.leaderstats["Stage 1 Completes"].Value + 1
print("I am being Touched")
end -- then statement end
end)
local event
event=Stage1Check.Touched:Connect(function(hit)
local humanoid= hit.Parent:FindFirstChild("Humanoid")
if humanoid ~=nil then
player.leaderstats["Stage 1 Completes"].Value = player.leaderstats["Stage 1 Completes"].Value + 1
print("I am being Touched")
event:Disconnect()
end
end)
The thing is. Touched event fires only once. It appears to fire multiple times because our characters keeps touching the part. But in reality it fires once for touching the part once.
The only work around I can think of is disconnecting the event, but that will never fire the event again if the brick is touched.
You can also try setting the “CanTouch” property of the part to false after it is fired.
Or use TouchEnded event to check when we stop touching the part.