I have a script setup that plays an animation and disables a damage script, it worked when I didn't have the damage script disabled being true and false
Animation Script:
local humanoid = game.Players.LocalPlayer.Character:WaitForChild('Humanoid') local right = script:WaitForChild('RightPunch') local left = script:WaitForChild('PunchLeft') local idle = script:WaitForChild('Idle') local kick = script:WaitForChild('Kick') local combo = script:WaitForChild('Combo') local enabled = false local Mouse = game.Players.LocalPlayer:GetMouse() local damScript = script.Parent:WaitForChild("PunchDamage")
Mouse.KeyDown:connect(function(key) if key == 'v' then local anim = humanoid:LoadAnimation(idle) if enabled == false then print('Ability Enabled') anim:Play() enabled = true elseif enabled == true then print('Ability Disabled') anim:Stop() enabled = false end end
if key == 'e'then local anim = humanoid:LoadAnimation(right) if enabled == true then anim:Play() damScript.Disabled = false wait(0.5) damScript.Disabled = true else print('Ability Not Equipped') end elseif key == 'q' then local anim = humanoid:LoadAnimation(left) if enabled == true then anim:Play() damScript.Disabled = false wait(0.5) damScript.Disabled = true else print('Ability Not Equipped') end elseif key == 'f' then local anim = humanoid:LoadAnimation(kick) if enabled == true then anim:Play() damScript.Disabled = false wait(0.5) damScript.Disabled = true else print('Ability Not Equipped') end end
end)
Damage Script:
local char = script.Parent local rhand = char:WaitForChild("RightHand") local lhand = char:WaitForChild("LeftHand") local lfoot = char:WaitForChild("LeftFoot") function rHandTouched(partHit) local hum = partHit.Parent:FindFirstChildWhichIsA('Humanoid') if hum then wait(.1) hum:TakeDamage(10) end end
function lHandTouched(partHit) local hum = partHit.Parent:FindFirstChildWhichIsA('Humanoid') if hum then wait(.1) hum:TakeDamage(10) end end
function lFootTouched(partHit) local hum = partHit.Parent:FindFirstChildWhichIsA('Humanoid') if hum then wait(.1) hum:TakeDamage(15) end end
rhand.Touched:Connect(rHandTouched) lhand.Touched:Connect(lHandTouched) lfoot.Touched:Connect(lFootTouched)
The scripts are in startercharacter scripts
It's best that you don't make a script in the player, and instead make the script one that can be cloned, so you only do damage when you want to.
Your way: To fix it, I would assume you'll have to add a wait() at the very start, but I'll look through the script and edit my answer as I see fit.
If you want to go with the way I mentioned, you would create a ServerScript and parent it to ReplicatedStorage. Set it's disabled to true. Then, clone it to the part you want to deal damage and set it's disabled to false. Use .Touched and a debounce.