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

Why does my sword only does damage once but then stops doing damage after?

I am currently working on a sword right now and everything is going perfectly, but my sword only does damage once when I swing my sword. If my swing my sword again, it would stop damaging. I have a BoolValue that is set as a debounce, and the debounce works perfectly fine. When the debounce is true, it is able to do damage, if it's false, then it doesn't. I make it where it defaults as true first, but right after it does damage, it is set to false, but after one second, it is set back to true, and since it's true, it should be able to do damage again, but it doesn't. Someone, please explain why and how to fix it. Thanks!

Local Script:

local CanAttack = true
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local idle = char:WaitForChild("Humanoid"):LoadAnimation(script.idle)
local attack = char:WaitForChild("Humanoid"):LoadAnimation(script.attack)
script.Parent.Equipped:Connect(function()
    idle:Play()
    script.Parent.Activated:Connect(function()
        if CanAttack then
            idle:Stop()
            attack:Play()
            CanAttack = false
            wait(1)
            attack:Stop()
			idle:Play()
            CanAttack = true
			script.Parent.CanDamage.Value = true
        end
    end)
end)
script.Parent.Unequipped:Connect(function()
	idle:Stop()
end)

Script:

script.Parent.Activated:Connect(function()
	
	script.Parent.blade.Touched:Connect(function(p)
		if script.Parent.CanDamage.Value ==  true then
			p.Parent.Humanoid:TakeDamage(20)
			script.Parent.CanDamage.Value = false
		end
	end)
end)

3 comments

0

Please dont repeat questions

0

Because you set the CanDamage value back to true on the client. Due to filtering, it'll only show on the client

0

I recommend a remote event to set it back

1 answer

✓ Accepted answer

It's simple. RemoteEvents can send data between the Client and the Server. A value cannot transport it between the two scripts. Just replace the BoolValue with a RemoteEvent and it should work.

Article for how to use Events: https://developer.roblox.com/ko-kr/articles/Remote-Functions-and-Events

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