Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years 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 1336 Moderation Voter
4 years ago
Edited 4 years 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 1336 — 4y
0
Thanks You So Much! This Worked! overwatcher54 11 — 4y
Ad

Answer this question