Click SurfaceGui button through part

Basically, i’m trying to make a Computer with programs that can be clicked.


In front of the SurfaceGui is a Screen that blocks the player from being able to click the buttons. Is there a way to “ignore” that screen so the players can click the buttons?
image
The ignore folder is for the TargetFilter so only the Computer can be seen through the Mouse, but i’m still not sure how to go from there

3 Likes

I don’t think there is a direct way to do this, but you can make it so when you are interacting the computer, it deletes temporarily the parts blocking it, so the player can click on those programs.

You can also check where the mouse has clicked on, then raycast or convert those coordinates to a world position and check if they are over that part, if they are, then do stuff.

1 Like

I already did the raycast part, can you tell me how to convert it to WorldPosition and check? Even documents or other posts can help.
My current code is

Mouse.Button1Down:Connect(function()
			if Mouse.Target then
				if Mouse.Target == Computer then
					local ray = Mouse.UnitRay
					ray = Ray.new(ray.Origin, ray.Direction)
				end
			end
		end)

You can check this post right here let me know if it helps in anything

1 Like

You can use workspace:Raycast() which accepts RayCastParams.

Example:

local params = RayCastParams.new()
params.FilterType = Enum.FilterType.Exclude
params.FilterDescendantsInstances = -- put a table of the parts you want it to ignore

And then you can implement this into your current code:

ray = workspace:Raycast(ray.Origin, ray.Direction, params)
1 Like

Thanks, i already switched to this version and now i added the params

I’m not sure exactly how i can incorporate this into my code, are there any other useful posts?

If you want to convert mouse position into world position than you can use workspace.CurrentCamera:ViewportPointToRay()

It’s basically mouse.Hit.p but better.

How to implement it:

local mousePos = UserInputService:GetMouseLocation() -- your gonna have to make a variable that gets user input service
local worldMousePos = workspace.CurrentCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.