When Player dies, starterpack local scripts stop working

you could use the eventfunction CharacterAdded to do that

1 Like

can i put the animation in character scripts? it clones automatically the thing in folder to character

Yes, that would work perfectly.

1 Like

so like this?

--//Services

local UserInputService = game:GetService("UserInputService")

--//Debounces

local punching = false

--//Player

local Player = game.Players.LocalPlayer

local Character = game.Workspace:WaitForChild(Player.Name)

local Humanoid = Character:FindFirstChildOfClass("Humanoid")

--// older

Punch = Instance.new("Animation")

Punch.AnimationId = "rbxassetid://"

PunchTrack1 = Humanoid:LoadAnimation(Punch)

--// newer

PunchTrack = Humanoid.FlipAnim

--//Coding

UserInputService.InputBegan:Connect(function(Input)

if Input.KeyCode == Enum.KeyCode.F and not punching then

PunchTrack:Play()

end

end)

I would suggest calling :WaitForChild() on the humanoid to wait for the animation, but once you’ve done that, it should work.

1 Like

like this? :
PunchTrack = Humanoid:WaitForChild("FlipAnim")

--//Coding
UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F and not punching then

		PunchTrack:Play()

	end
end)

so this happened:
output:
20:13:38.037 - Infinite yield possible on ‘Workspace.ClanShad27.Humanoid:WaitForChild(“FlipAnim”)’

20:13:38.039 - Stack Begin

[20:13:38.041 - Script 'Players.ClanShad27.PlayerScripts.Flip [STARTERPACK]', Line 17](rbxopenscript://www.dummy.com/dummy?scriptGuid=%7BB2383028%2D0B92%2D4740%2DAB6E%2DDD5CA2F3814C%7D&gst=2#17)

20:13:38.042 - Stack End

can you explain the output above?

You’re getting that error because you did not put the animation inside the player Humanoid. Try this.

Punch = Instance.new("Animation", Humanoid)
1 Like

now, it playing the animation check game now, but when the player dies the script doesnt work anymore

If I understand your problem properly, I would recommend moving the script to StarterPlayerScripts, this will make it run better and should work even after a player dies.

1 Like

it are already in :confused: thx for your attention

1 Like

Can you check the game? please, try to open ur roblox studio and use the script and see if it work or not

Put this code inside the StarterCharacterScripts

local UserInputService = game:GetService("UserInputService")

--//Debounces

local punching = false

local Player = game.Players.LocalPlayer

local Character = game.Workspace:WaitForChild(Player.Name)

local Humanoid = Character:FindFirstChild("Humanoid")

local Punch = Instance.new("Animation",script)
-- Punch.Name = "FlipAnim"
Punch.AnimationId = "rbxassetid://03155342819"

local PunchTrack1 = Humanoid:LoadAnimation(Punch)

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F and not punching then
		PunchTrack1:Play()	
	end
end)
1 Like

so, it worked before dying, then after died it didnt worked anymore

It should work did you do that?

1 Like

oh, i thonk you said playerscript :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning:

Thanks so much, i hope you win the ‘programmer’ tag :smiley:

How did the script inside StarterPack disappear after you died?
I actually need the script to do that for my game but I don’t know how to make it do that.

just set the script’s parent to the player backpack when they spawn, that way you can define wether or not it will happen again after he dies or just when they first enter the game