Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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

Asked by 3 days ago

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

Log in to vote
0
Answered by
TGazza 205 Moderation Voter
2 days ago
Edited 2 days ago

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
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 TGazza 205 — 2d
0
Thanks You So Much! This Worked! overwatcher54 11 — 1d
Ad

Answer this question