Ray.new() and workspace:FindPartOnRay… are both legacy API and shouldn’t be used anymore. They’ve actually been deprecated very recently. Instead, you should use the newer and more upgraded raycasting:
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
-- blacklist is essentially the same thing as ignore list
raycastParams.FilterDescendantsInstances = {}
-- put the stuff you want in the ignore list inside that table.
local origin, direction = -- fill in with your own origin/direction
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
if raycastResult then -- it's nil if it doesn't hit anything, so check
print(raycastResult.Instance) -- the part that it hit
print(raycastResult.Position) -- the position where the ray hit
print(raycastResult.Material) -- the material of the part it hit
print(raycastResult.Normal) -- the surface normal where it hit
end
Some of the benefits of this newer API is that you can reuse RaycastParams (you don’t have to re-create it every time, just once at the top of your script) AND you don’t have to create a ray object every time you want to raycast. It’s just 1 function.
Also, there’s no more checking the docs for the proper argument/return order. Since it’s a table now, you can set the options/read the result in any order you want.
Oh thats interesting. However i would call my self a noob scripter im scared to break the whole script when i try to add this new raycasting would you help me to set this up ?
You can use the above example I showed you, but just copy and paste your existing values into the new script. If anything breaks, you can just revert it.
Thats the problem i dont understand raycasting very good i dont know what to replace and what to change.
Askasta#6514 is my discord im free for a call if you are interested.
If you want to learn more about raycasting I’d recommend reading these articles:
All of them are pretty short and once you understand them you’ll be able to make a proper gun. All of the articles have working script samples to help you as well.
i dont wanna make a gun myself. I just dont want a shoooting gun. My gun itself has other features aswell
how would i modificate this current one to use the new raycast
I already provided an example which shows you how to use the new raycasting and gave you additional resources to help you. If you don’t want to learn how, then I don’t want to help you (i’m not going to spoonfeed).
its not about the how. Its just the current one when you hit a object wich it should wallbang it then hits the object and behind the object create a new ray.
Also it has a feature if the player mouse is aiming somehwere it cant shoot meaning behind him the gun will then switch to the gun barrel and just shoot foward. this is to disable people shooting behind them