I dont know what this script kinda doesand i kinda need help

To do that (in serverside script):

local Players = game:GetService("Players")
local Animation = script.Animation -- It should be animation object and you need to set id in it.

Players.PlayerAdded:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	
	Humanoid.Died:Connect(function() -- This function firing when player is died
		player.CharacterAdded:Wait() -- this waits until the character fully loaded
		-- in this section you can script anything after player is respawned. Example:
		local AnimationToPlay = Humanoid:LoadAnimation(Animation)
	    AnimationToPlay:Play()
	end)
end)

Here is for local script:

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

local Animation = script.Animation -- inside the script

Humanoid.Died:Connect(function()
	Player.CharacterAdded:Wait() -- this waits until the character fully loaded
	-- in this section you can script anything after player is respawned. Example:
	local AnimationToPlay = Humanoid:LoadAnimation(Animation)
	AnimationToPlay:Play()
end)

Those scripts i prepared for you is to play animation on character. You should add animation object inside the script and set the “AnimationId” property to the ID of your animation (you can get this from roblox website). Also, if there is anything you don’t understand, let me know(in script). Local scripts should be in starterplayerscripts,startercharacterscripts,startergui(maybe) etc. serverscripts can be created in everywhere

wait why do you need a local script too and how do you know like where to always put your scripts

i always since 11 always had trouble with that

Server sided scripts: run by the SERVER
Client sided scripts: run by your client only (or PC) with some exceptions.

so the client is the own player ohh i get it

Local scripts are for individual players. For example getting their inputs, keys that they pressed even for the phone etc. Serversidescripts are for all the server like countdown for a map or rarity systems etc. Also serversidescripts are shown for all players but local scripts not everytime.

ohhhh makes sense now thx , inputs are services right?
but and keys? do keys like store values?

I mean’t like pressing K key on your keyboard and detecting that.

ohhh i gotta learn that too i think i should and try to read almost all the api docs cuz tbh i am kinda bad so i am looking to improve

Main reason local scripts are used is because the server can’t handle too many tasks (animations, tweening, key inputs, etc) Since it will causes massive lag.

Should be best left for the more important tasks like calculations and stuff.

For example:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input,gpe) -- InputBegan (when key begin to be pressed)
	if gpe then return end -- if player is chatting then don't detect the keys.
	
	if input.KeyCode == Enum.KeyCode.K then -- Detecting Key
		print("You pressed K")
	end
end)

ohhh but like wdym many tasks like i cant put too many scripts in them or something

i never understood one thing in that script when can u put like (function(input,gpe) and sometimes it s only funtion(), does that like store that value into the function?
And where can i used the Enum service can u tell?

Please try to take the time to understand how the code works before asking questions.
Function runs a preset code that you have defined earlier.
The strings in the brackets are the variables or data you passed through.

ohhhh ok i will try to undertsnad

Try to think of code like this, if you input something into a machine, then something happens in the machine, then you get a output.

if this then that.

function definedfunction (input ) then
– do something in here to get your output
return output
end

definedfunction(yourinputgoeshere)

Imagine you create a server for a game and allocate 4 GB of RAM to it. If the server was large, RAM usage would increase. If the server runs out of RAM, the server will slow down. This is what is happening with the roblox. For this reason we are trying to make clients (players) handle this situation so there will be less lag with game.

As i used userinputservice in the script, when we call a function most likely there will be parameters inside the function. You may understand with this:

local Players = game:GetService("Players") --Just getting the service of all players

Players.PlayerAdded:Connect(function(inside here will be parameters) --When player added This function will be called
	
end)

inside the paranthesis beside the function is where we get the parameters coming from the events or things we want to pass. You can’t pass parameters when you using events but when you create a function that doesn’t have a event you can pass parameters here is another example:

function ListOfBakery(Bread,Donut)
	print(Bread,Donut) -- this will print bread and donut
end

ListOfBakery("Baguette","Chocolate Donut") --Calling the function

-- when i call the function that doesn't use event i can set parameters for function

EDIT: Parameters carry information. Like when we use playeradded event function’s parameter will
give us the player.

ohhh i kinda understand now.
just one thing are functions litteraly like variables except they have a callback event?

variables are for assignment or referring to something already defined.
local variable = “this is a variable”

functions are where you want something to happen.

Also if you don’t even know what is a variable or events then go watch AlvinBlox (he have new tutorial) or peasfactory (he is old but gold you can understand basics) etc.