Hi, how do i make this script not function once the part was touched once? here is my code:
local debounce = 3
local bin = true
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and bin then
bin = false
local HD = Humanoid:GetAppliedDescription()
HD.HeadScale = HD.HeadScale * .2
HD.DepthScale = HD.DepthScale * .2
HD.WidthScale = HD.WidthScale * .2
HD.HeightScale = HD.HeightScale * .2
Humanoid:ApplyDescription(HD)
wait(debounce)
bin = true
end
end)
local Touch
Touch = script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
local HD = Humanoid:GetAppliedDescription()
HD.HeadScale = HD.HeadScale * .2
HD.DepthScale = HD.DepthScale * .2
HD.WidthScale = HD.WidthScale * .2
HD.HeightScale = HD.HeightScale * .2
Humanoid:ApplyDescription(HD)
Touch:Disconnect() -- Disconnect the function, so it won't fire again
end
end)
You can use the :Disconnect() function like TOP_Crundee123 said, or you could do it without using a connection at all. By calling :Wait() on an event, the code will yield until that event is fired. So here is an alternate solution that will also work.
script.Parent.Touched:Wait()
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and bin then
bin = false
local HD = Humanoid:GetAppliedDescription()
HD.HeadScale = HD.HeadScale * .2
HD.DepthScale = HD.DepthScale * .2
HD.WidthScale = HD.WidthScale * .2
HD.HeightScale = HD.HeightScale * .2
Humanoid:ApplyDescription(HD)
wait(debounce)
bin = true
end
Edit: Actually I don’t know how you would use the hit parameter in this case.