Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
TtuNkK 37
4 years ago

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)
0
Please dont repeat questions HappyJakeyBoy 67 — 4y
0
Because you set the CanDamage value back to true on the client. Due to filtering, it'll only show on the client mybituploads 304 — 4y
0
I recommend a remote event to set it back mybituploads 304 — 4y

1 answer

Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago

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

Ad

Answer this question