Last night I couldn't figure out how to get a Touched connection to end when needed - someone suggested I use the :Disconnect() function. I looked into it and I can't quite figure out how to get it to work, adding it to my script just causes lag and a multitude of errors. I'm pretty sure I formatted the script wrong and put the :Disconnect() in the wrong spot, but I don't know where else to place it.
local connection
function onPunchDamageFired(Player)
local rightArm = Player.Character:FindFirstChild("Right Arm")
rightArm.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and CanDmg == true and hit.Parent.Humanoid.Health > minimumhealth then
hit.Parent.Humanoid:TakeDamage(dmg)
CanDmg = false
wait(1.5)
CanDmg = true
print 'punch succeeded'
else
print 'humanoid not found!'
end
connection:Disconnect()
end)
connection = rightArm.Touched:Connect(onPunchDamageFired)
end
punchdamageEvent.OnServerEvent:Connect(onPunchDamageFired)

2 comments
By hashmap do you mean dictionary? I have never heard of a hashmap before now.
Essentially.