Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
Is your character r6 greatneil80 2647 — 3y
0
Yes Itz_Visually 17 — 3y

3 answers

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago

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
Log in to vote
0
Answered by
kepiblop 124
3 years ago

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
0
Ok, Ill try it and let you know Itz_Visually 17 — 3y
0
Alright! kepiblop 124 — 3y
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. Itz_Visually 17 — 3y
0
Oh shoot i just noticed that, thanks for reminding me! You wanna do player.Character for the char. kepiblop 124 — 3y
View all comments (3 more)
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 Itz_Visually 17 — 3y
0
shoot im sorry i am late but uhh you make something like this kepiblop 124 — 3y
0
local Char = player.Character kepiblop 124 — 3y

Answer this question