I recently started learning ray-casting
I’m making a gun and a gunshot particle will appear at where you shot.
But how do I find the end of the raycast?
local ray = Ray.new(script.Parent.Position, Vector3.new(0,30,0))
local m = game.Players.LocalPlayer:GetMouse()
while wait(1) do
local hit,position = workspace:findPartOnRay(ray, (m.Hit.p))
if hit then
print(hit.Name)
end
end
Create a part with Instance.new() right where the ray ends, put a particle emitter in that part, emit it, then delete the part. If you need explaining on how to do that lmk.
Well. Theres a bit of an error
it says unable to cast value to object
local m = game.Players.LocalPlayer:GetMouse()
local ray = workspace:RayCast(script.Parent.HumanoidRootPart.Position,m.Hit.Position)
while wait(1) do
local hit,position = workspace:findPartOnRay(ray, m.Hit.Position)
if hit then
print(hit.Name)
local part = Instance.new("Part")
part.Position = position
part.Parent = workspace
part.Anchored=true
end
end