Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a more efficient way to update a selectionBox's adornee than by using RenderStepped?

I'm building a tool that selects a block if it has a certain name. I've hooked the function that accomplishes this up to RenderStepped, but I feel like this is an inefficient way of doing it. It feels unnecessary to do this 60 times per second. Is there a better way to accomplish this? Hooking the function up to mouse.Move and camera.Changed doesn't work either, because if, say, another player moves in front of the player's mouse, the selectionbox's adornee won't update (to nil). Thanks.

function updateSelectionBox()
	if mouse.Target then
		if mouse.Target.Name == "Boundary" or mouse.Target.Name == "Object" then
			selectionBox.Adornee = mouse.Target
		else
			selectionBox.Adornee = nil
		end
	end
end

RunService.RenderStepped:connect(updateSelectionBox)

2 comments

0

you could do wait(0.1). A bunch of people probably wont even notice

0

you could use UserInputService for this

2 answers

✓ Accepted answer

There is no problem doing it this way. The client should be able to handle it.

You could fire the function every time Mouse.Target is different.

local currentTarget = nil

local function selectionBox(target)
	if (target) then -- check if exist
		-- change adornee
	else
		-- don't show selection
	end
end

RenderStepped:Connect(function()
	if (mouse.Target ~= currentTarget) then
		currentTarget = mouse.Target
		selectionBox(currentTarget)
	end
end)

Use game:GetService(“RunService”).Heartbeat since it adapts to the players frames per second so it reduces lag. I guess that basically all u could do.

This discussion is preserved as it was. New answers, comments, and votes are closed.