✓ Accepted answer
Your problem is here
RightArm.Touched:connect(function(hit)
local ehum = hit.Parent:FindFirstChild("Humanoid")
if ehum and ehum ~= plr.Character.Humanoid then
ehum:TakeDamage(10)
return hit
end
end)
The thing about events is that, when connected, they continue to work until the event is disconnected (using :disconnect()), the object that the event is child of (Ex. Right Arm) gets destroyed, or the script that the event is connected (this script) gets destroyed.
Also, do not use :connect() because it's old, use :Connect().
What you want to do, is to disconnect the Touched event.
First, we need to assign this event to a variable.
local touchedEvent = RightArm.Touched:Connect(function(hit)
local ehum = hit.Parent:FindFirstChild("Humanoid")
if ehum and ehum ~= plr.Character.Humanoid then
ehum:TakeDamage(10)
return hit
end
end)
Then after some time, disconnect the event.
touchedEvent:Disconnect()
After that, this script will no longer listen to the touched event.
plr = game.Players.LocalPlayer
Kick = script:WaitForChild("KickAnimation")
Punch = script:WaitForChild("PunchAnimation")
mouse = plr:GetMouse()
RightArm = plr.Character:WaitForChild("Right Arm")
RightLeg = plr.Character:WaitForChild("Right Leg")
True = true
mouse.KeyDown:connect(function(key)
if key == "q" then
if not True then return end
True = false
local aTrack = plr.Character.Humanoid:LoadAnimation(Punch)
aTrack:Play()
local touchedEvent = RightArm.Touched:Connect(function(hit)
local ehum = hit.Parent:FindFirstChild("Humanoid")
if ehum and ehum ~= plr.Character.Humanoid then
ehum:TakeDamage(10)
return hit
end
end)
wait(2)
True = true
touchedEvent:Disconnect()
end
end)
1 comment
Thank you for the help I understand now and I accept this answer.