Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The animations load until the player resets. Why?

So the script works fine until the player resets and respawns. Whenever I click on the button, it doesn't do anything anymore.

This is a LocalScript located within: TextBox>Frame>ScreenGui>StarterGui

playerChar = game:GetService("Players").LocalPlayer.Character
playerHumanoid = playerChar:WaitForChild("Humanoid")

checkValue = game:GetService("ReplicatedStorage").Values.animIsPlaying
running = game:GetService("ReplicatedStorage").Values.isRunning

	-- Animations
local sitAnim = Instance.new("Animation") 
sitAnim.AnimationId = "rbxassetid://03225667771"

local sittingAnim = Instance.new("Animation")
sittingAnim.AnimationId = "rbxassetid://03225675930"

-- Animation tracks
local sitTrack = playerHumanoid:LoadAnimation(sitAnim) 
local sittingTrack = playerHumanoid:LoadAnimation(sittingAnim)

UIS = game:GetService("UserInputService")

debounce = false
check = 0



script.Parent.MouseButton1Click:connect(function()
	
		if check == 0 and checkValue.Value == false and running.Value == false and playerHumanoid then
			print("Working!")
		
		playerHumanoid.WalkSpeed = 0
		sitTrack:Play()
		wait(0.1)
		sittingTrack:Play()
		playerHumanoid.WalkSpeed = 0
		
		check = 1
    	checkValue.Value = true

		elseif check == 1 and checkValue.Value == true then
		sittingTrack:Stop()
		playerHumanoid.WalkSpeed = 16
		
		check = 0	
		checkValue.Value = false
	
		
		end
		wait(1.5)
		debounce = false

end)

1 answer

It seems like you are not resetting the script when the player resets, on line 2:

playerHumanoid = playerChar:WaitForChild("Humanoid")

When a player dies, if I remember well, the humanoid also gets deleted in order to spawn a new one, this script should work:

playerChar = game:GetService("Players").LocalPlayer.Character

checkValue = game:GetService("ReplicatedStorage").Values.animIsPlaying
running = game:GetService("ReplicatedStorage").Values.isRunning

    -- Animations
local sitAnim = Instance.new("Animation") 
sitAnim.AnimationId = "rbxassetid://03225667771"

local sittingAnim = Instance.new("Animation")
sittingAnim.AnimationId = "rbxassetid://03225675930"

-- Animation tracks
local sitTrack = playerHumanoid:LoadAnimation(sitAnim) 
local sittingTrack = playerHumanoid:LoadAnimation(sittingAnim)

UIS = game:GetService("UserInputService")

debounce = false
check = 0



script.Parent.MouseButton1Click:connect(function()

        if check == 0 and checkValue.Value == false and running.Value == false and playerHumanoid then
            print("Working!")
	playerHumanoid = playerChar:WaitForChild("Humanoid")
        playerHumanoid.WalkSpeed = 0
        sitTrack:Play()
        wait(0.1)
        sittingTrack:Play()
        playerHumanoid.WalkSpeed = 0

        check = 1
        checkValue.Value = true

        elseif check == 1 and checkValue.Value == true then
        sittingTrack:Stop()
        playerHumanoid.WalkSpeed = 16

        check = 0   
        checkValue.Value = false


        end
        wait(1.5)
        debounce = false
end)

If this does not work, Look for a property called Reset on Respawn in your Gui's properties settings

*extra useless content probably:

I believe that what makes player model be deleted and respawned again is the settings in game.Players called Character Auto Loads or something like that...*

--yee--

This discussion is preserved as it was. New answers, comments, and votes are closed.