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

How do I add sparkles to a player using a script?

I have a code that I'm trying to use where if a certain player joins, it will make a new sparkles instance inside the torso of that player. Here's what I have, but it's not working. I'm testing this in Roblox Studio, so the name is Player.

game.Players.PlayerAdded:connect(function(plr)
    local name = plr.Name
    if name == "Player" then
        sparkles = Instance.new("Sparkles", game.Workspace.Player.Torso)
		sparkles.Enabled = true
		sparkles.SparkleColor = (255, 255, 0)
	 end
end)

2 comments

0

00:15:37.277 - Player is not a valid member of Workspace

0

I replied with an answer that should help.

1 answer

✓ Accepted answer

Your error is setting the color, you tried to set a Color3 value as a non-Color3 value.

game.Players.PlayerAdded:connect(function(plr)
    local name = plr.Name
	repeat wait() until plr.Character -- Wait for character
	local char = plr.Character
    if name == "Player1" then --The name for a player in studio is Player1.
        local sparkles = Instance.new("Sparkles", char.Torso)
        sparkles.Enabled = true
        sparkles.SparkleColor = Color3.new(255, 255, 0)--Error here
     end
end)

Onrespawn

game.Players.PlayerAdded:connect(function(plr) --Define Player
	plr.CharacterAdded:connect(function(char) --Define Character
    local name = plr.Name
    if name == "Player1" then 
        local sparkles = Instance.new("Sparkles", char.Torso)
        sparkles.Enabled = true
        sparkles.SparkleColor = Color3.new(255, 255, 0)
     end
	end)
end)

8 comments

0

After fixing that, it still didn't work.

0

Are you sure? I tested it in studio and it worked fine.

0

char.Torso <-- This was edited in the script. Didn't see it.

0

Are there any issues with the script, do you need more explanation, or are you fine with it?

0

This is fine, but I also kind of want to know how to get it to stay on respawn.

0

The second script should fix that.

0

Thank you! If I had 5 rep I would upvote you!

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