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

Why Will The SelectionBox Not Appear?

I don't understand, the selection box won't show up no matter what I try... Maybe it's the event? If so, what would the correct event be since it's a brick?

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

Mouse.Target.MouseEnter:connect(function()
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
SB.Parent = Mouse.Target
SB.Adornee = Mouse.Target
end
end)

Mouse.Target.MouseLeave:connect(function()
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
SB.Parent = nil

end
end)

1 answer

The problem is that nothing that Mouse.Target can be has the property MouseLeave or MouseEnter. What you need to do is make a check everytime the mouse is moved to check if the mouse has a Target and if the Target is was you are looking for.

local player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local selectionBox = Instance.new("SelectionBox")

mouse.Move:connect(function()
	if mouse.Target then
		if mouse.Target.Parent:FindFirstChild("Humanoid") then
			selectionBox.Parent = Mouse.Target
			selectionBox.Adornee = Mouse.Target
		else
			selectionBox.Parent = nil
			selectionBox.Adornee = nil
		end
	else
		selectionBox.Parent = nil
		selectionBox.Adornee = nil
	end
end)

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