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

How Do I Enable A Selection Box When A Player Is Looking At A Part?

At the moment I am trying to make a game that will have a building mechanic that resembles Minecraft. I am trying to make it outline a part when the player hovers there mouse over it but I cannot seem to figure out how. Here is my current code.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

while true do
	if Mouse.Target then
		local blockTest = Mouse.Target:FindFirstChild("SelectionBox")
		if blockTest then
			blockTest.Transparency = 0
		end
	end
	wait(0.01)
end

1 answer

✓ Accepted answer

Might not work online but heres a working example for you to work apon.

You may need to control the selectionbox through a server script and hook it up with remote functions for other people/players to see the selection box!.

Code (Local Script):

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local SelectionBox = Instance.new("SelectionBox",script)

while true do
    if Mouse.Target ~= nil then
		SelectionBox.Adornee = Mouse.Target
		SelectionBox.Parent = Mouse.Target
	else
		SelectionBox.Adornee = nil
		SelectionBox.Parent = script
	end
    wait(0.01)
end

2 comments

0

Just confirmed it. You still see the selection box as you mouse over objects But other players Don't see it. And i doubt you will be able to move/change the blocks from a local script unless the blocks are "local" and not in the workspace

0

Thanks You So Much! This Worked!

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