I’m making a shovel tool that allows you to dig through terrain, but when entering first person, I can’t dig. This was working fine before I added a filter that would allow the shovel to only dig through mud. Any help is appreciated.
Can you put print(result)
before the line if result and result.Instance == game.Workspace.Terrain...
so we can see what your raycast is returning? My initial guess is that the raycast is hitting the shovel rather than the dirt
Might be Hitting the shovel, use RaycastParams
, something like this:
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {shovel}
local cast = workspace:Raycast(..., ..., params)
You aren’t filtering the player’s character in the ray so when you click in first person you’re just clicking on yourself.
It’s probably just hitting your own character, just use ray cast params and exclude the player character or all player character
Yes, the raycast is hitting not only the shovel, but my character as well.
After filtering, it returns nil for some reason.
Can we see your code for the updated raycast?
multiply ray.Direction by a number (you used 500 in your original code) so its longer, right now its only one stud long since ray is a UnitRay (a one stud long ray) and thus wont hit anything
also slightly off topic but it may be more performant to create the raycastparams outside of the event, so you dont have to create a new one every click. Very small optimization but good coding practices go a long way
Thank you for the advice. I’ll look into it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.