Im trying to make it so a function happens every time a player respawns or joins through a local script. Please let me know
Here is code that may help you:
local PlayerService = game:GetService("Players") local function onCharacterAdded(character) --Run respawn code here end local function onPlayerAdded(player) --Run join code here player.CharacterAdded:Connect(onCharacterAdded) end PlayerService.PlayerAdded:Connect(onPlayerAdded)
What it does: it gets the service called Players
and then connects an event called PlayerAdded
under Players
to a function we made called onPlayerAdded
. Then, in the onPlayerAdded
function, we use the player
instance obtained by the player
parameter included in the PlayerAdded
event to connect an event called CharacterAdded
, which is fired when the player's character
respawns, to a function we made called onCharacterAdded
.