Looking for how to destroy this thing?

I want to destroy an object that is generated from another function. This is the function that adds the object:

am.OnClientEvent:Connect(function(v)
	local mark = Instance.new("Highlight", v.Parent)
	mark.Name = "Mark"
	mark.FillTransparency = 1
	mark.OutlineColor = Color3.new(1, 1, 0)
	wait(7)
	hasmark = false
	mark:Destroy()
end)

And this is the code for the function that destroys the object:

grom.OnClientEvent:Connect(function(v)
	local mark = v.Parent:FindFirstChild("Mark")
	mark:Destroy()
	print("here")
end)

Both are in the same local script, and both are the result of a Client → Server → Client RemoteEvent. The “print(“here”)” part of the script works, so it’s not like there’s an error, but the “mark” will not be destroyed.

P.S: Both functions must remain in a localscript.

1 Like

It seems like you’re already attempting to destroy the mark here though?

1 Like

Yes, but it does not get destroyed.

Try

am.OnClientEvent:Connect(function(v)
	local mark = Instance.new("Highlight", v.Parent)
	mark.Name = "Mark"
	mark.FillTransparency = 1
	mark.OutlineColor = Color3.new(1, 1, 0)
	wait(7)
	hasmark = false
	v.Parent:WaitForChild("Mark"):Destroy()
end)

grom.OnClientEvent:Connect(function(v)
	local mark = v.Parent:WaitForChild("Mark")
	mark:Destroy()
	print("here")
end)

AM is the function that adds the highlight. It then deletes it 7 seconds later. The GROM function is supposed to destroy the mark prematurely.

Your script also does not work either way.

what exactly doesn’t work? Highlight appears or not? For me the script works fine

Check if there’re multiple highlights due to the remote running multiple times. That’s an error/bug on its own but here’s the solution for it:

local function destroy(v: Instance)
	for _, child in pairs(v.Parent:GetChildren()) do
		if child.Name == "Mark" and child:IsA("Highlight") then
			child:Destroy()
		end
	end
end

--example
grom.OnClientEvent:Connect(function(v)
	destroy(v)
	print("here")
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.