Raycast assistance needed

Hi, I’m trying to use raycast to basically detect whether the player’s mouse hits the delete button which is a surfacegui on the object.

local Params = RaycastParams.new() 

Params.FilterType = Enum.RaycastFilterType.Include
		Params.FilterDescendantsInstances = {workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(Player.PlotClaimed.Value)).Objects:GetChildren()}

local ray = game.Workspace:Raycast(Player.Character.RightHand.Position, (mouse.Hit.Position - Player.Character.RightHand.Position)*100, Params)
			

The grills are loaded based on prior placements by the player via datastore which means I can’t directly refer to the surfacegui. What I need assistance for is how would I refer to a model to actually work for FilterDescendantsInstances?

image

image

1 Like

I am confused. Why have a ray cast when you can make a button? I don’t think a ray is necessary.

But if you really want to use ray cast why don’t you loop through a folder where you put the grill and see if they have a child which is a surfacegui then insert all these in a table then use whitelist / include for raycast filter type and yeah. Can’t provide script example since I am on mobile sorry.

Edit : or you can do something like if ray.hit is a surfacegui or something if it exists

I’m trying to apply raycast because the delete button (trash icon) only appears when your inventory is open, which is client-side. When the inventory is closed, the button is not visible.

The issue is that the objects (models) you see infront (6 ice color looking ones) are cloned from ReplicatedStorage. I would like to use a filter for these models but I’m not able to because it doesn’t refer to any of the children parts under it so I was wondering if there was any efficient solution to basically address this without having to spam for loops or remote events.

Using :GetDescendants() addressed the issue.

Just wondering if you remove get descendants or get children and just keep the path to object wouldn’t it still work? I am sorry I kinda forgot how ray filters works.

I used getdescendants to basically get every single part from the model. :GetChildren() itself does not work.

No no I meant what happened if you do this :


Params.FilterType = Enum.RaycastFilterType.Include
		Params.FilterDescendantsInstances = {workspace.PlayerSpaces.AreasAvailable:FindFirstChild(tostring(Player.PlotClaimed.Value)).Objects}

Yeah. It doesn’t work. You get nil

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