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

How can a local script in playerscripts work even if they reset?

Asked by 8 years ago

This is the code, it works somewhat:

wait(1)
print("Loaded")
local Player = script.Parent.Parent
local Mouse = Player:GetMouse()
local character = Player.Character
local Tools = Player.Backpack
local startgear = Player.StarterGear
local replicatedStorage = game.ReplicatedStorage.Tools
local animation = script.Parent.Animation
local animTrack = character.Humanoid:LoadAnimation(animation)


function makeGearStart()
    for i,v in pairs(Tools:GetChildren()) do 
        v:clone().Parent = replicatedStorage
    end
end
makeGearStart()

-------------------------------------------
function setSpeed(speed)
    character.Humanoid.WalkSpeed = speed -- speed function
end


function holdingTool()
    for _, child in pairs(character:GetChildren()) do
    if child.ClassName == "Tool" then
     child:Destroy()
    end
end 
end

function giveBackTool()
    for i,v in pairs(replicatedStorage:GetChildren()) do 
        v:clone().Parent = Tools
    end
end




Mouse.KeyDown:connect(function(Key) -- main thing
if Key == "x" then 
    if character.Humanoid.WalkSpeed > 0 then
        setSpeed(0)
        Tools:ClearAllChildren()
        holdingTool()
        animTrack:Play()
    else
        setSpeed(16)
        giveBackTool()
        animTrack:Stop()
    end

end
end)

But when the character resets it no longer works. The script is a local script in StarterPlayerScripts. Help make this work even after reset? Thanks

1
Disable and reenable this from another script. That might fix it, but it's not a great solution. GoldenPhysics 474 — 8y
1
I think I fixed it. GoldenPhysics 474 — 8y

Answer this question