-- Sorry if this has been posted before; I looked up local scripts and removing parts on death but I couldn't find anything specifically related to my question.
How is this done?
Details:
- When a player spawns, they spawn with a small floating red orb above them
- This is created by a local script in the Player's StarterPack.
- That floating orb is known as Player.Name.."'s_BasicOrb"
How can I remove that orb when the local player either dies or disconnects?
Here is the code I've gotten to work so far:
local Player = game.Players.LocalPlayer
Player.CharacterAdded:connect(function(PlayerBody)
BasicOrb = Instance.new("Part", game.Workspace)
BasicOrb.Name = Player.Name.."'s_BasicOrb"
BasicOrb.Size = Vector3.new(2,2,2)
BasicOrb.Anchored = true
BasicOrb.Shape = "Ball"
BasicOrb.Material = "Neon"
BasicOrb.BrickColor = BrickColor.new("Really red")
while wait() do
BasicOrb.CFrame = PlayerBody.Head.CFrame:toWorldSpace(CFrame.new(0,10,0))
end
end)
Issues:
- Orb does not despawn on death. This is because I can't seem to make a function that actually removes the orb.
- Script gets stuck in the while loop, so anything else written in the script is ignored.
- Orb is basically duplicated because
- When the player dies, the first orb is not removed
- When the player respawns, another orb is created
- I want the orb to be recreated each time the player respawns (that way, if the orb is deleted somehow, the player can reset and the orb will pow exist again.)
Any valid input would be much appreciated by me, as I have been struggling with this issue for a few days now. #NewbieIssues.
PS: I can't just say
Player.Died:connect(function() BasicOrb:remove())
can I? I mean... I don't have any playtesters, but how would the game know to remove the part that it spawn for the local player and not a different player's part?

1 comment
PPS: I've been doing some testing of the current local script and I've noticed that the floating orb flickers. It didn't do that when I had the script as a simple game.Players.PlayerAdded:connect(OrbFollow) function, so I'm not sure why it'd change when it's a local script. If you'd like to answer this question, too, that'd be very helpful :3