Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Can I Make A Particle Emitter That Attaches To The Player On Join?

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.

2 comments

0

Is your character r6

0

Yes

3 answers

✓ Accepted answer

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

7 comments

0

Ok, Ill try it and let you know

0

Alright!

0

Wait, just to make sure where do I put the char argument? I wanna have the feeling of getting it right at the first time.

0

Oh shoot i just noticed that, thanks for reminding me! You wanna do player.Character for the char.

0

Wait, I don't get it lol, sorry my head has been rlly tired. Would I make a variable or would I pass the arguments char in something? And precisely what parenthesees

0

shoot im sorry i am late but uhh you make something like this

0

local Char = player.Character

This discussion is preserved as it was. New answers, comments, and votes are closed.