Object Not Destroying: debug not working

I have a function which should teleport a player (which works fine) and then should destroy “Highlight” within the player, the function I’m using is below;

local function TeleportBack(player)
	if player and player.Character then
		local chr = player.Character
		local humanoidRootPart = chr:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			humanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame
			print("Teleporting ", player.Name, " to spawn location.")
		else
			print("HumanoidRootPart not found in ", player.Name, "'s character.")
		end

		local highlight = chr:FindFirstChild("Highlight")
		if highlight then
			highlight:Destroy()
			print("Highlight destroyed for ", player.Name)
		else
			print("Highlight not found for ", player.Name)
		end
	else
		print("Invalid player or player.Character is nil.")
	end
end

When the function is called, the debug returns “Highlight destroyed” however it does not get destroyed. I can confirm that “Highlight” is in the player when the function is called. Any insight or help would be greatly appreciated, thanks.

1 Like

I see 3 eventual problems:

  • Is there multiple Highlights in your character?
  • Another object have “Highlight” as name in your character? if yes, then use FindFirstChildWhichIsA to get the Highlight object.
  • Is there another variable in your script, above your function, with “highlight” as name?
1 Like

Just checked it out, I found an issue where the function that gives the player Highlight is called again when the player is teleported in a seperate part of the script.

I’m pretty sure that changing that will resolve this, but I’ll let you know if it doesn’t. Thanks alot for your help if it does!

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