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
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.
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.
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)
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.
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.
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.