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

How to add a tagging system to this sword script?

Asked by 4 years ago

I have tried everything I could find about creator tags and I just can't seem to find a way to fit it in this script. Some help would be appreciated!

local TOOL = script.Parent
local BLADE = TOOL.Blade
local ANIMS = {}
for index, CHILD in pairs(script:GetChildren()) do
    if CHILD.Name == "Slash" then
        table.insert(ANIMS,CHILD)
    end
end
local FIGHT = false
local FRIENDLYFIRE = TOOL.FriendlyFire
local IDLEANIM = nil
local TRAIL = BLADE.Trail

function Slash()
    if FIGHT == false then
        local HUM = TOOL.Parent:FindFirstChildOfClass("Humanoid")
        if HUM then
            TOOL.Slashing.Value = true
            BLADE.Swing.Pitch = math.random(8,12)/10
            BLADE.Swing:Play()
            TRAIL.Enabled = true
            local SHOUT = script.Grunt:Clone()
            SHOUT.Parent = HUM.Torso
            SHOUT:Play()
            SHOUT.Pitch = math.random(8,12)/10
            game:GetService("Debris"):AddItem(SHOUT,2)
            local BOD = Instance.new("BodyPosition",HUM.Torso)
            BOD.Position = HUM.Torso.CFrame * CFrame.new(0,0,-6).p
            BOD.P = 750
            BOD.D = 35
            BOD.MaxForce = BOD.MaxForce*25
            local ANIM = HUM:LoadAnimation(ANIMS[math.random(1,#ANIMS)])
            ANIM:Play()
            FIGHT = true
            local HIT = BLADE.Touched:Connect(function(TOUCHED)
                if TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then
                    local HUM = TOUCHED.Parent:FindFirstChildOfClass("Humanoid")
                    local PASS = true
                    if game.Players:FindFirstChild(HUM.Parent.Name) and FRIENDLYFIRE.Value == false and TOUCHED.Parent:FindFirstChildOfClass("ForceField") == nil then
                        PASS = false
                    end
                    if PASS == true then
                        HUM:TakeDamage(TOOL.Damage.Value)
                    end
                end
            end)
            ANIM.Stopped:Connect(function()
                TOOL.Slashing.Value = false
                BOD:Remove()
                TRAIL.Enabled = false
                HIT:Disconnect()
                wait()
                FIGHT = false
            end)
        end
    end
end

TOOL.Activated:Connect(function()
    Slash()
end)

TOOL.Equipped:Connect(function()
    local HUM = TOOL.Parent:FindFirstChildOfClass("Humanoid")
    if HUM and script:FindFirstChild("Idle") then
        IDLEANIM = HUM:LoadAnimation(script.Idle)
        IDLEANIM:Play()
    end
end)
TOOL.Unequipped:Connect(function()
    if IDLEANIM then
        IDLEANIM:Stop()
    end
end)

1 answer

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
4 years ago
Edited 4 years ago

You can check beforehand if the target is alive and will die with the damage you are going to deal, then apply the code you want.

You can also create an objectvalue to the player who took damage with a value of the player that dealt it. Then use a Humanoid.Died event to check if there is such objectvalue to apply what you want. Remember to make these objectvalues destroy after some time, so it wont stack and count players who dealt damage a long time ago.

This last option is better to use when you want to check if multiple players dealt damage at the time, for things such as share exp on RPGs or just count kill score for more than one player.

0
I've gotten it to create the tag and everything, but I can't get it to set the value to the player who dealt the damage. jackfrcsty 15 — 4y
Ad

Answer this question