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

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

Asked by
Djinous 45
8 years ago

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)
0
00:15:37.277 - Player is not a valid member of Workspace Djinous 45 — 8y
0
I replied with an answer that should help. UniversalDreams 205 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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)
0
After fixing that, it still didn't work. Djinous 45 — 8y
0
Are you sure? I tested it in studio and it worked fine. UniversalDreams 205 — 8y
0
char.Torso <-- This was edited in the script. Didn't see it. Djinous 45 — 8y
0
Are there any issues with the script, do you need more explanation, or are you fine with it? UniversalDreams 205 — 8y
View all comments (4 more)
0
This is fine, but I also kind of want to know how to get it to stay on respawn. Djinous 45 — 8y
0
The second script should fix that. UniversalDreams 205 — 8y
0
Thank you! If I had 5 rep I would upvote you! Djinous 45 — 8y
Ad

Answer this question