Hi, I'm working on a particle emitter that attaches to the player when they join, for some reason it's isn't working. No errors and nothing prints.
Here is the script:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(Char) game.ReplicatedStorage.Auras.Lightning:Clone().Parent = Char.Torso end) end)
It's a ServerScript in StarterCharacterScripts.
If your script is inside of "StarterCharacterScripts" then it runs when your character spawns, in your script you use [PlayerAdded] signal which fires when player joins, it is nonsense, in your case the best fix would be putting this script inside of "ServerScriptService", there it will run somewhere at the server start.
You also should be using [WaitForChild] to be sure that [Char.Torso] is replicated because it does not have to be when you index it right after he spawns:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(Char) game.ReplicatedStorage.Auras.Lightning:Clone().Parent = Char:WaitForChild("Torso") end) end)
This should fix it, for maximum efficiency tho you should use variables to not index [...Auras.Lighting] everytime the character spawns.
--\\ServerScriptService local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local Lighting = ReplicatedStorage.Auras.Lighting Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(Char) Lighting:Clone().Parent = Char:WaitForChild("Torso") end) end)
Try to use Char.PrimaryPart.
Because depending on the character of each player, there may not be a Torso, but HumanoidRootPart, so try to use the PrimaryPart.
game.ReplicatedStorage.Auras.Lightning:Clone().Parent = Char.PrimaryPart
You should try characteradded:Wait() instead Since its in startercharacterscripts, you should use players:GetPlayerFromCharacter() instead As genilsonotavio said, you should use primary part too.
Here is some code with everything fixed
local player = game.Players:GetPlayerFromCharacter(script.Parent) player.CharacterAdded:Wait() game.ReplicatedStorage.Auras.Lightning:Clone().Parent = Char.PrimaryPart