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

Could I receive help on an issue with sword scripts and dealing damage to enemies?

Asked by
Xanth 0
5 years ago
Edited 5 years ago

So the main goal of these scripts is for the sword to play an animation I made whenever you click and then during the animation the sword should be able to damage. Any other time I do not want the sword to cause damage when touched by an enemy. Only during the animation.

The issue I am having is that the sword is playing the animation and swinging correctly, however, for some reason I cannot get the damaging script to work. The script that does the damage is a normal script and the animation script is a local script. Whenever the animation plays, the script enables the ability for the blade of the sword to be touched by making the damage script no longer disabled. Whenever it finishes the animation, it disables it once again. This means that the touch script should be active for the duration of the sword swing animation, however, it is not. The enemies do not get destroyed.

I'm assuming this has to do with some sort of weird interaction between local and global variables that I haven't figured out yet. Anyway, here are the scripts. Any help would be very appreciated!

Damage Script (global script nested inside of the blade of the sword)

function onTouch(hit)
    if hit.Name == "Unsoul" then
        hit:Destroy()
    end
end

script.Parent.Touched:Connect(onTouch)

Animation Script (local script also nested inside of the blade of the sword)

isActive = false

function onSwing()
    if isActive == false then
        isActive = true
        local attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
        attack:Play()
        script.Parent.Damage.Disabled = false
        wait(.5)
        script.Parent.Damage.Disabled = true
        wait(.5)
        isActive = false
    end
end

script.Parent.Parent.Activated:Connect(onSwing)
0
why are they both global DeceptiveCaster 3761 — 5y
0
whoops let me edit that. animation script is local. my bad Xanth 0 — 5y
0
Oh nevermind. Tried doing the same thing except with a remote event connected to the part where it disables/enables to script that references the global script. Problem solved. Xanth 0 — 5y
0
Can't you just also use a server script for the damage? ScrubSadmir 200 — 5y

Answer this question