hello, so i have a problem, so like i got a script in serverscriptservice which spawns a highlight in the player’s character when joining. (it works)
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local highlight = game.ReplicatedStorage.Highlight:Clone()
highlight.Parent = character
highlight.FillTransparency = 1
highlight.OutlineTransparency = 1
end)
end)
but now i need to make the highlight’s properties change once the script is related in some way to the character. that script is in an attachment in the player’s humanoidrootpart. (script.Parent.Parent… = char)
here is the localscript i made that changes the properties once the attachment is found but doesnt change it back when the attachment is gone.
local character = game.Players.LocalPlayer.Character
local folder = character:WaitForChild("Aura")
local highlight = character:WaitForChild("Highlight")
while true do
if folder:FindFirstChildWhichIsA("Folder") then
highlight.FillColor = Color3.fromRGB(9, 70, 0)
highlight.FillTransparency = 0.5
highlight.OutlineColor = Color3.fromRGB(9, 70, 0)
highlight.OutlineTransparency = 0
end
wait()
end
I kinda understand what you are trying to do in here. But, I can say for sure this is not a good approach to do it.
First, on a localscript you are “waiting” for an instance called “Highlight” to spawn inside “player” instance owner of this localscript.
And you placed the “Highlight” instance from a server script upon join, inside the “Character” instance of the player (meaning, the Model of the player, not the Player instance)
So you will never find it.
But. You dont have to do this in order to fire functions when player is found, got its stuff, etc, not locally or server side.
I suggest you change the entire approach. First explain what exactly you want to achieve.
When player joins, a Highlight instance is added to it and the colors should be this (), after, all data from player is loaded?.. maybe, the color is gotten from their Datastore?.. idk btw, Highlight thing in my experience is very buggy, but it works fine if you use it carefully
so when the parent of the script (an attachment named “Aura”) is in the humanoidrootpart, then the highlight should change color and become visible but if theres no attachment in the humanoidrootpart, then it should turn invisible again
You can do it with only one script in server without needing the local script, or the use of remotes.
When player joins, clone the Highlight instance, place it in the Character, and connect ChildAdded and ChildRemoved to the HRP to listen when the Attachment named “Aura” is added and removed from the HRP. And do the stuff you want on each case.
You could try something like this:
local Highlight = game.ReplicatedStorage:WaitForChild("Highlight")
-- Properties to change in Highlight
local AuraParams = {
FillTransparency = 0.5,
FillColor = Color3.fromRGB(9, 70, 0),
OutlineColor = Color3.fromRGB(9, 70, 0),
OutlineTransparency = 0,
Enabled = true
}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if not plr:HasAppearanceLoaded() then
plr.CharacterAppearanceLoaded:Wait()
end
warn(char, "loaded")
-- Create the highlight
local newHighlight = Highlight:Clone()
newHighlight.Parent = char
--newHighlight.Enabled = true
local HRP = char:WaitForChild("HumanoidRootPart")
-- Fired everytime something is parented inside the HRP
HRP.ChildAdded:Connect(function(aChild)
if aChild.Name == "Aura" then -- if the added child's name is Aura do stuff
warn("got aura")
-- Iterate a table of properties to change Highlight params
for param, data in pairs(AuraParams) do
newHighlight[param] = data
end
end
end)
-- Everytime a child is removed from HRP
HRP.ChildRemoved:Connect(function(aChild)
if aChild.Name == "Aura" then
newHighlight.Enabled = false
end
end)
end)
end)
Im not exactly sure what you mean by “Attachment”. I do think on the instance called Attachment, a green invisible ball that is inside the parts of the character model.
Idk how you are handling that, “giving an Attachment” to the HRP of the player.
So I tested the above code with this little button on workspace that gives an Attachment to the player’s HRP just to check the above code works works.
workspace:WaitForChild("Part"):WaitForChild("ClickDetector").MouseClick:Connect(function(plr)
local char = plr.Character
if char then
local HRP = char:FindFirstChild("HumanoidRootPart")
if HRP then
if HRP:FindFirstChild("Aura") then
HRP.Aura:Destroy()
else
local newAttch = Instance.new("Attachment")
newAttch.Name = "Aura"
newAttch.Parent = HRP
end
end
end
end)