I am trying to add a system to my game that highlights an object on the client. Here is the code:
-- Client
game.ReplicatedStorage.RemoteEvents.Highlight.OnClientEvent:Connect(function(highlight: Highlight, OnTop: boolean, parent: Instance)
local highlightclone = highlight:Clone()
local function setup()
task.wait(0.1)
highlightclone.Parent = parent
print(parent)
end
task.spawn(setup)
if OnTop then
highlightclone.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
else
highlightclone.DepthMode = Enum.HighlightDepthMode.Occluded
end
end)
-- Server
local function Highlight(player: Player, highlight: Highlight, OnTop: boolean, parent: Instance)
RemoteEvents.Highlight:FireClient(player, highlight, OnTop, parent)
end
Highlight(player, Highlights.Legendary, true, GearHandleClone)
The parent prints nil, but there are no errors. Any help?
I don’t even know what you’re trying to do as you haven’t explained this really well.
Why don’t you just repeatedly get the mouse.Target and check if the part has a boolvalue called “HighlightEnabled” and then just clone a new highlight for the player which is a child of that part? When the mouse.Target isn’t on a part that has that boolvalue it will delete the highlight?
Edit: That’s what I did for my own highlight stuff for my own game ^
So I have a system that should highlight something on the client side when an event is triggered. The highlight is created, but the .Parent property is never updated.
-- Client
game.ReplicatedStorage.RemoteEvents.Highlight.OnClientEvent:Connect(function(Player, Highlight, OnTop, parent)
local highlightclone = highlight:Clone()
local function setup()
task.wait(0.1)
highlightclone.Parent = parent
print(parent)
end
task.spawn(setup)
if OnTop then
highlightclone.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
else
highlightclone.DepthMode = Enum.HighlightDepthMode.Occluded
end
end)
-- Server
local function Highlight(Highlight, OnTop, parent)
RemoteEvents.Highlight:FireClient(Highlight, OnTop, parent)
end
Highlight(Highlights, OnTop, parent)
I have rewritten the code a little. It’s kind of messy. Also is the “game.ReplicatedStorage.RemoteEvents.Highlight.OnClientEvent:Connect(function(Player, Highlight, OnTop, parent)” a ServerScript or Local? There is no point in doing a remote event if its local (Player only) because RemoteEvents are usually used from a Local script to trigger an event for the whole server to see.
Can you print the parent from the server side and the client side right after the code starts so we can see if you are sending the correct variable in the first place?