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.