StarterPlayerScripts not working after player resets

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait()
local Hum = Character:WaitForChild("Humanoid")

local Debounce = true

local UIS = game:GetService("UserInputService")

local PunchEvent = game:GetService("ReplicatedStorage"):WaitForChild("PunchEvent")

UIS.InputBegan:Connect(function(input, process)
	if Player:WaitForChild("Busy").Value == false then
		if input.KeyCode == Enum.KeyCode.Q and not process and Debounce then
			Hum:LoadAnimation(script.RightPunch):Play()
			Debounce = false
			PunchEvent:FireServer()
			task.wait(0.75)
			Debounce = true
		end
	end
end)

I made a script which makes the player punch when they press Q. after the player resets, I get an error saying “Cannot load the AnimationClipProvider Service.” and the script stops working

Put this script in StarterCharacterScripts. StarterPlayerScripts are for localscripts that run once when the player first joins the game. StarterCharacterScripts run every time the character is loaded/respawns.

1 Like

This is the simplest solution, if you want to stick with the ‘StarterPlayerScripts’ container route then you’ll need to use the local player’s 'CharacterAdded and ‘CharacterRemoving’ signals/events.

local Game = game
local UserInputService = Game:GetService("UserInputService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer

local Connection

local function OnInputBegan(InputObject, GameProcessed)
	if GameProcessed then return end
	--Do code.
end

local function OnCharacterAdded(Character)
	Connection = UserInputService.InputBegan:Connect(OnInputBegan)
end

local function OnCharacterRemoving(Character)
	Connection:Disconnect()
end

Player.CharacterAdded:Connect(OnCharacterAdded)
Player.CharacterRemoving:Connect(OnCharacterRemoving)