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

LocalScript in sword tool breaking after player's death/reset?

Asked by 5 years ago

I am currently working on a game that includes a sword script. I made a localscript for the actual mechanisms of the tool. Here's my localscript.

local Cooldown = true
local RandomPos = math.random(0,1)
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:wait()
local Hum = Char:WaitForChild('Humanoid')
local Anim = Hum:LoadAnimation(script.Parent.Animation)
local leaderstats = Player:WaitForChild("leaderstats")
    script.Parent.Activated:Connect(function()
        if Cooldown == true then
            Cooldown = false
            script.Parent.Handle.sword_swing1:Play()
            leaderstats.Yen.Value = leaderstats.Yen.Value + script.Parent.Interval.Value
            local AddCashAlert = Player.PlayerGui.CashRecievedGui.Frame.TextLabel
            AddCashAlert.Text = "+"..script.Parent.Interval.Value
            Anim:Play()
            AddCashAlert.TextTransparency = 0
            script.Parent.Handle.Trail.Enabled = true
            for i = 0,1,.1 do
                AddCashAlert.TextTransparency = i
                wait()
            end
            wait(.7)
            Cooldown = true
            script.Parent.Handle.Trail.Enabled = false
        end
    end)
    script.Parent.Unequipped:Connect(function()
        Anim:Stop()
        script.Parent.Handle.PutIn:Play()
    end)
    script.Parent.Equipped:Connect(function()
        script.Parent.Handle.PutOut:Play()
    end)

But however, when the player dies from an NPC or dies from reseting, the script doesn't work anymore. No animations, no trails, nothing. Could anyone help and give me a thorough explaination for this? Thanks.

P.S, Sorry for the formatting. I don't know how to fix that issue, so if you know the answer, please comment on this post.

0
Is there any thing in the script that is telling the player to delete something? Sorry can't read your script its cause of the formatting thing, also is there anything that the npcs cause to delete the players effects? 123nabilben123 499 — 5y
0
No, I checked each NPC script and nothing includes deleting anything. Also, I tried using debounce, but it still doesn't work. Sensei_Developer 298 — 5y

Answer this question