Dark_12400

Give Sparkles

Oct 23rd, 2020
955
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Players = game:GetService("Players")
  2.  
  3. local function onCharacterAdded(character)
  4.     -- Give them sparkles on their head if they don't have them yet
  5.     if not character:FindFirstChild("Sparkles") then
  6.         local sparkles = Instance.new("Sparkles")
  7.         sparkles.Parent = character:WaitForChild("Head")
  8.     end
  9. end
  10.  
  11. local function onPlayerAdded(player)
  12.     -- Check if they already spawned in
  13.     if player.Character then
  14.         onCharacterAdded(player.Character)
  15.     end
  16.     -- Listen for the player (re)spawning
  17.     player.CharacterAdded:Connect(onCharacterAdded)
  18. end
  19.  
  20. -- Iterate over each player already connected
  21. -- to the game using a generic for-loop
  22. for i, player in pairs(Players:GetPlayers()) do
  23.     onPlayerAdded(player)
  24. end
  25. -- Listen for newly connected players
  26. Players.PlayerAdded:Connect(onPlayerAdded)
RAW Paste Data