Highlights disappearing after rooms are cloned enough times

In my game there are client-sided highlights that act in place of ProximityPrompts.

Though they function as intended for the first few clones of a room, after a certain point they no longer appear. Aside from that, interaction works as intended.

I haven’t found anyone facing a similar problem to this yet.

Code handling the visuals for the locker. The door uses similar code, so I won’t be attaching it unless necessary. They face the same issue regardless.

local camera = workspace.Camera
local player = game.Players.LocalPlayer
local inLockerFX = game.Lighting:WaitForChild("InLocker")

local UserInputService = game:GetService("UserInputService")

local playerGui = player:WaitForChild("PlayerGui")
local screengui = playerGui:WaitForChild("InLockerVignette")

local lockerVignette = screengui:WaitForChild("ImageLabel")

local TweenService = game:GetService("TweenService")

local door = script.Parent
local doorParent = door.Parent
local camPos = door.Parent:WaitForChild("CamPos")

local proximityPrompt = script.Parent.ProximityPrompt

local highlight = doorParent:WaitForChild("Highlight")

local tweenInfo = TweenInfo.new(0.3)
local tweenInfo2 = TweenInfo.new(0.3, Enum.EasingStyle.Cubic)

local tween1 = TweenService:Create(highlight, tweenInfo, { OutlineTransparency = 0 })
local tween2 = TweenService:Create(highlight, tweenInfo, { OutlineTransparency = 1 })
local tween3 = TweenService:Create(camera, tweenInfo2, { CFrame = camPos.CFrame })

local tweenUI1 = TweenService:Create(lockerVignette, tweenInfo, { ImageTransparency = 0 })
local tweenUI2 = TweenService:Create(lockerVignette, tweenInfo, { ImageTransparency = 1 })

local tweenLighting1 = TweenService:Create(inLockerFX, tweenInfo, { NearIntensity = 60 })
local tweenLighting2 = TweenService:Create(inLockerFX, tweenInfo, { NearIntensity = 0 })

local hideEvent = script.Parent:WaitForChild("Hide")
local exitEvent = script.Parent:WaitForChild("Exit")

local playerSafeValue = player:FindFirstChild("Safe")


-----------------------------------------------------------------------------------------------


local isInLocker = false

proximityPrompt.Triggered:Connect(function(player)
	if not isInLocker then
		hideEvent:FireServer("1")
		camera.CameraType = Enum.CameraType.Scriptable
		tween3:Play()
		tweenUI1:Play()
		tweenLighting1:Play()
		isInLocker = true
		playerSafeValue = true
	end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard and not gameProcessed then
		local keyPressed = input.KeyCode

		if keyPressed == Enum.KeyCode.E and isInLocker then
			exitEvent:FireServer("2")
			camera.CameraType = Enum.CameraType.Custom
			tweenUI2:Play()
			tweenLighting2:Play()
			isInLocker = false
			playerSafeValue = false
		end
	end
end)


proximityPrompt.PromptShown:Connect(function()
	tween1:Play()
end)

proximityPrompt.PromptHidden:Connect(function()
	tween2:Play()
end)

I’ve attached a video of the issue.

There is a client sided render limit on highlights of 31. Even if the highlight’s enabled property is set to false it will still take up a slot.
Highlight | Documentation - Roblox Creator Hub

In that case, what’s the best way to counter this issue?

You’d probably have to destroy the highlights when they aren’t in use, maybe when you change floors the highlights on every other floor are destroyed and the highlights on the current floor are created. You could also destroy them in the Prompt Hidden Function and create them in the Prompt Shown function.

I’ll share with you one of the codes I’ve used, it does a similar thing but it won’t reach the highlight limit.

local MouseData = {
	Target = {
		Instance = nil,
		Highlight = nil,
	},
	ClickPosition = nil,
	_LeftClickConnection = nil
}

function TargetChanged(Target: Instance?, Position: Vector3?)
	RunService:UnbindFromRenderStep('TargetUpdate')

	local PreviousHighlight: Highlight? = MouseData.Target.Highlight
	if PreviousHighlight then
		local TweenInstance = Tween(PreviousHighlight, {OutlineTransparency = 1, FillTransparency = 1})
		TweenInstance.Completed:Connect(function()
			PreviousHighlight:Destroy()
		end)
	end
	
	if Target and Position then
		Tracer.Visible = true
		Mouse.Icon = 'rbxasset://textures/Cursors/KeyboardMouse/ArrowCursor.png'
		
		local NewHighlight = script.Highlight:Clone()
		MouseData.Target.Highlight = NewHighlight
		NewHighlight.Adornee = Target
		NewHighlight.Parent = Target

		Tween(NewHighlight, {OutlineTransparency = 0.2, FillTransparency = 0.8})

Use only 1 highlight, put it in the script for the highlights thingy and assign the adornee to the part you are hovering your mouse on though if you dont want the highlight to adornee to the parts that dont need a highlight you can add a value to the parts that do need a highlight, check for that value and if it is there the highlight would adornee to it.

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