Problem with raycast

Why is this not working correctly? I’m creating a raycast for my projectile, but it turns out it’s not detecting the parts correctly sometimes it, there are times it detects, but there are times it goes straight through


is done in server script

https://gyazo.com/b36fb972e31844f0c62ef0d5437e9f4f
I’ve already used the new raycast and the old one, but they both had the same problem

Maybe try making the multiplier higher, like *4 or *5 instead of *2. And I’d suggest converting your code to the new version of RayCasting (yes I noticed that you said that even the new RayCast doesn’t work properly). Something else you could do is to make an attachment in front of your sphere and get the LookVector from there so it’s more precise.

2 Likes

Did you mean like that? the problem still remains

Could you provide your code in between three `? (The key to the left of your 1 key)
Like this:
image
It makes the code much easier to read

			while game:GetService("RunService").Heartbeat:Wait() do
				local ray = Ray.new(Beam.Position, Beam.Attachment.CFrame.lookVector)
				local part, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {c , game.Workspace.Game.Explosion, game.Workspace.Game.Projectile})
					if part ~= nil then
					Beam:Destroy()
					local Explosion = RP:WaitForChild("Part"):Clone()
					Explosion.Parent = game.Workspace.Game.Explosion
					Explosion.CFrame = CFrame.new(position)
					
					local info = TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
					local tween = TweenService:Create(Explosion, info, {Size = Vector3.new(40,40,40), Transparency = 1})
					tween:Play()
					
					tween.Completed:Connect(function()
						Explosion:Destroy()
					end)
			break
			end
	end

like this?

Just curious, is there a reason why you have all of this wrapped in a while loop? From the gif you provided it seems like you can run this check whenever the player clicks

because it’s a projectile, I think it has to be constantly updated. But is there a problem?

It doesn’t need to be constantly updated, and is possibly the reason why this problem occurs.

local ray = Ray.new(Beam.Position, Beam.Attachment.CFrame.lookVector)
				local part, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {c , game.Workspace.Game.Explosion, game.Workspace.Game.Projectile})
					if part ~= nil then
					Beam:Destroy()
					local Explosion = RP:WaitForChild("Part"):Clone()
					Explosion.Parent = game.Workspace.Game.Explosion
					Explosion.CFrame = CFrame.new(position)
					
					local info = TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
					local tween = TweenService:Create(Explosion, info, {Size = Vector3.new(40,40,40), Transparency = 1})
					tween:Play()
					
					tween.Completed:Connect(function()
						Explosion:Destroy()
					end)

try running all of that code when the player clicks:

--LocalScript

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	-- Anything inside of here will run when a player clicks
end)

now it’s not working,I do not know why

I already solved, thank you guys