What am I trying to do? I am simply trying to clone a highlight from ReplicatedStorage and set its parent to the character on spawn. This is my first time messing with ReplicatedStorage.
What’s the issue? The issue is that the highlight isn’t appearing in general onto the character.
What solutions have I tried so far? I have messed around a bit with tweaking the script but have not figured out the real reason for it not appearing due to there being no errors in my output.
Highlighting local player only: what @weakroblox35 said.
Could you please elaborate on the goal? Based on your code snippet I’m understanding you are trying to highlight all players. You ought to indeed use those two connections. The problem I see is, they are connected too late, and don’t account for players that are already playing the game.
Code
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local character -- local player's character
local outline = game.ReplicatedStorage.Highlight
-- each new player
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(newChar)
outline:Clone().Parent = newChar
end)
end)
-- all player's that were in the game before
for _,player in Players:GetPlayers() do
if player.Character then
outline:Clone().Parent = player.Character
end
end
-- finally, local character
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
outline:Clone().Parent = character
Alternatively, you can have a server script do the above, which sets a highlight to all players.
local outline = game:GetService("ReplicatedStorage").Highlight
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
outline:Clone().Parent = character
end)
end)