Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Damage script not working when it is enabled, using disabled = true/false?

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

1 answer

✓ Accepted answer

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.

1 comment

0

How would you do your way? I just can't think of a way how.

This discussion is preserved as it was. New answers, comments, and votes are closed.