Error cloning highlight on client side

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?

2 Likes

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 ^

On the server I believe you should be firing it as a client event.

-- Server
RemoteEvents.Highlight:FireClient(player, Hightlights.Legendary, true, GearHandleClone)

Hope this resolves the issue :smiley:

His code is still working, he just simplified it a lot. I don’t think this is the problem.

Sorry about that, I added the function to the code

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.

No problem! The second thought I had was to add the following snippet to the client:

highlightclone.Adornee = parent
highlightclone.Enabled = true

Well instead of this why don’t you just put it in one line? I don’t get why you have a “setup function”

highlightclone.Parent = parent

I put it in a task.spawn, but I don’t believe that is really important

Why do you have a task.spawn for this? It is just setting the parent property. Try removing it.

That would work, however, I need to edit the highlight from outside the event, so that wouldn’t work for that purpose

I already tried that, it didn’t work

How exactly are you editing the highlight outside the event?

-- 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?

I cannot print the highlight from the server side, as it is added client-side.

I’m talking about the parent variable.

-- 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)

Try removing the first argument in the FireClient() “player”

OnClienEvent can only be triggered from the client. Also FireClient always needs a target player who you are firing the event for. :smiley:

The script should work it’s just obviously going wrong somewhere and we can’t really help you as you need to debug further.