How do I make a surface GUI able to be used from behind a brick?
Here is a video of the problem.
https://gyazo.com/0b82d49be1964ff48763fc68ae4b6f4f
Have you already tried utilizing the AlwaysOnTop
property?
Yes, but there are other bricks on top of it.
I’m assuming you’re using mouse.Target
, so you could try and connect a function to mouse.Move
that will only detect parts you want to highlight; however you won’t be able to configure this for going through multiple parts layered on top of eachother
local mouse = player:GetMouse()
local whitelistedNames = {
["TileSelection"] = true -- whatever your tile is named
}
mouse.Move:Connect(function()
local target = mouse.Target
-- ignore the current target if it isn't whitelisted so it can try and hit a whitelisted one
if target and not whitelistedNames[target.Name] then
mouse.TargetFilter = target
end
end)
Once again, this won’t work with multiple non-whitelisted parts atop eachother.
Hopefully someone can come along with a better solution, if this works for you then that’s great
There will be multiple parts layered on top of each other, is there any other way you can think of? Like some way I can make the parts on top let the mouse through? Thank you.
What you could do to make the sample above work with multiple layered parts is have the selection part and visuals separated. The hierarchy could look like this:
In this example, "selection"
is a whitelisted name.
“visuals” will be ignored.
You could then ignore target.Parent
rather than target
itself, and that will ignore all the parts that are part of the visual aspect of the model. (make sure to ignore workspace as a parent to filter out due to terrain being able to be a target)
Quick example I made:
https://gyazo.com/f8d394bb0db987c4d2d5d219751c8b23
Code for the above:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local whitelistedNames = {
["selection"] = true -- whatever your tile is named
}
local lastTarget
mouse.Move:Connect(function()
local target = mouse.Target
-- ignore the current target if it isn't whitelisted so it can try and hit a whitelisted one
if target then
if whitelistedNames[target.Name] then
lastTarget = lastTarget or target
target.gui.label.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
else
if target.Parent ~= workspace then -- ignore workspace b/c it'll ignore *everything*
print("filter:", target.Parent)
mouse.TargetFilter = target.Parent
end
end
end
if lastTarget and lastTarget ~= target then
lastTarget.gui.label.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
lastTarget = nil
end
end)
I will try this out tomorrow thank you!