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

How do I fix this script from not working when dieing or resetting?

Asked by
FBS_8 25
5 years ago

So I have this sprint script but it doesn't work if I die or reset and I can't find out the problem

local UIS = game:GetService("UserInputService")
local p = game:GetService("Players").LocalPlayer
local c  = p.Character or p.CharacterAdded:Wait()
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4588222471"
local RunAnimation = c:WaitForChild("Humanoid"):LoadAnimation(anim)
UIS.InputBegan:Connect(function(i,a)
    if not a then
        if i.KeyCode == Enum.KeyCode.LeftShift then
            c:WaitForChild("Humanoid").WalkSpeed = 20
            RunAnimation:Play()
        end
    end
end)

UIS.InputEnded:Connect(function(i,a)
    if not a then
        if i.KeyCode == Enum.KeyCode.LeftShift then
            c:WaitForChild("Humanoid").WalkSpeed = 13
            RunAnimation:Stop()
        end
    end
end)
0
roblox is dumb. a quick fix might be a wait(1) at the start of the script big_thonk 0 — 5y

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
5 years ago

Redefine the character and AnimationTrack when the character is loaded.

p.CharacterAdded:Connect(function(char)
    c = char
    RunAnimation = c:WaitForChild("Humanoid"):LoadAnimation(anim)
end)
0
After the player dies, "c" points to an object that no longer exists and "RunAnimation" is an animation loaded on a humanoid that is also nonexistent. compUcomp 417 — 5y
0
How would I implement this? FBS_8 25 — 5y
0
You would put the code I posted somewhere in your script. compUcomp 417 — 5y
0
I already figured it out thx FBS_8 25 — 5y
Ad

Answer this question