I wish to have my raycast only interact with the predetermined model, and nothing else. How would I do this? I’ve tried this
local params = RaycastParams.new()
params.FilterDescendantsInstances = {script.Parent}
params.FilterType = Enum.RaycastFilterType.Include
Yet, my raycast is still interacting with other instances or not interacting with anything. Any help would be greatly appreciated! Below you’ll find the code responsible for creating the raycast. just to ensure I have everything written fine.
local Rock = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Pickaxe = Character:WaitForChild("Pickaxe")
local Handle = Pickaxe:WaitForChild("Handle")
local Count = 0
local params = RaycastParams.new()
params.FilterDescendantsInstances = {script.Parent}
params.FilterType = Enum.RaycastFilterType.Include
Hitbox.Touched:Connect(function(player)
local function Check()
if Handle:GetAttribute("IsActivated") == true then
Count += 1
local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2, params)
print (Cast)
if Cast then
if Cast.Instance.Name ~= Rock.Name then return end
else
return
end
end
end
repeat task.wait(1) Check() until Count == 5
OreTouchedEvent:FireServer(Rock)
Count = 0
end)
It looks like you are only putting script.Parent into the raycast parameters.
You should be including all the items the raycast is allowed to hit in the FilterDescendantInstances array.
As stated in the first link I posted, this can be done by simply adding the items to a collision group and using the filter’s array to check that group.
Just search collision or collisiongroup in the same site (create.roblox.com) that the other links I posted go to.
Go to the Documents tab to do your search.
Have you added the CollisionGroup?
Have you selected all the Parts (I don’t think you can add models) you want the raycast to hit and clicked the + button next to the collision group in the Collision Group window?
If an item is in a group you’ll see it in the Part’s CollisionGroup Property. If it doesn’t say Rock then you know it’s not added.
what do u wish it to do? u need to change the filter type of raycast info to Include instead of Exclude and then put the model inside of the table and it will only interact with the models inside of the table
I’m rather confused as to why this isn’t working as intended… It should work, given the parameters and the way it is setup, but it doesn’t even get to the cast part. The raycast is seemingly not touching anything…
Here’s my code to possibly have more information as to why it isn’t working.
local Rock = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Pickaxe = Character:WaitForChild("Pickaxe")
local Handle = Pickaxe:WaitForChild("Handle")
local Count = 0
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {script.Parent.Hitbox}
Hitbox.Touched:Connect(function(player)
local function Check()
if Handle:GetAttribute("IsActivated") == true then
Count += 1
local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2, params)
print(Cast)
if Cast then
if Cast.Instance.Name ~= Rock.Name then return end
else
return
end
end
end
repeat task.wait(1) Check() until Count == 5
OreTouchedEvent:FireServer(Rock)
Count = 0
end)
Whenever I click, which changes an attribute within the handle of the pickaxe tool that I’m using, it doesn’t seem to be getting picked up by the hitbox getting touched for some odd reason.
Also, this isn’t the case with the ores created in my testing area, those work just fine, but when I attempted to implement the system in my actual game, this problem I’m now facing reared its ugly head.
Usually that issue is related to the fact that studio runs the ‘server’ and the client both on your computer.
In the actual game you’re running on the Roblox server and your client.
I’m definitely not an expert but is this script a localscript or server script?
Where is this script located?
I think the problem is your including the thing its supposed to be hitting, which is the hitbox, not the actual stuff its supposed to be hitting which is the ores in this case. i dont think you even need to use raycasting for this it might just be better to use .touched or region3 to detect what the pickaxe is hitting