Having issues with RaycastResult

oh oops change 1000 to like -1000 so its on opposite direction!

Seems to have done the trick, no idea why!

100% consistency now- but why did that work?
Also, what about when I shoot in the sky? I don’t know how to fix that, it doesn’t fire if you shoot into the sky

Uhhhh Mouse.Hit.p isnt really reliable try using ScreenToPointRay lol ez

What? Do you mean Camera:ScreenPointToRay()?

1 Like

Ray.new is not deprecated. The new WorldRoot::Raycast API does not use Ray, but there may be other APIs in the future which do, and the type still gets returned from ScreenPointToRay.

2 Likes

Oh, gotcha. I misunderstood, because Ray.new() wasn’t used.

How would I make it so the Ray can be cast when no RaycastResult is passed?

Just use the ray properties, Ray.Origin and Ray.Direction

So I know this isn’t my post and i’m not supposed to ask questions here, but I had the exact same issue and @v_kyuu 's script did not work on me.
If you could help me that would be great :frowning:

This is my script (pls help)
if skillName == "Fireball" then
	
	local isHit = false
	
	local fireball = spells:WaitForChild("Fireball"):Clone()
	fireball.Parent = vfx
	game:GetService("Debris"):AddItem(fireball, 5)
	fireball.CFrame = humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * 10
	
	local rayOrigin = fireball.Position
	local rayDestination = mousePosition
	local rayDirection = rayDestination - rayOrigin

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {character, vfx}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.IgnoreWater = true

	local raycastResult = workspace:Raycast(character:WaitForChild("Head").Position, (fireball.Position - mousePosition).Unit * -1000, raycastParams)
	
	if not raycastResult then return end
	
	combatModule.PlayAnimation(humanoid, skillConfig:WaitForChild("AnimationID").Value)
	combatModule.CharacterFaceCursor(humanoidRootPart, mousePosition)
	humanoid.WalkSpeed = 0
	
	wait(0.75)

	humanoid.WalkSpeed = 20
	fireball.Transparency = 0
	
	task.spawn(function()
		
		local screenGui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui"))
		game:GetService("Debris"):AddItem(screenGui, 0.5)
		screenGui.IgnoreGuiInset = true
		screenGui.Name = "FireballEffect"
		
		local frame = Instance.new("Frame", screenGui)
		frame.BackgroundTransparency = 1
		frame.Size = UDim2.new(1,0,1,0)
		frame.BackgroundColor3 = Color3.fromRGB(255, 50, 0)
		ts:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {BackgroundTransparency = 0.8}):Play()
		
	end)
	
	fireball.Touched:Connect(function(hit)
		if hit.Parent.Name == character.Name then return end
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:WaitForChild("Shield").Value == false then
			if table.find(hits, hit.Parent) then return end
			if not table.find(hits, hit.Parent) then
				if not isHit then
					isHit = true
					combatModule.Hit(player, hit, sounds:WaitForChild("Hit"), values:WaitForChild("DefaultDamage").Value * skillConfig:WaitForChild("DamageMulti").Value)
					table.insert(hits, hit.Parent)
				end
			end
		end
	end)
	
	for i, particle in pairs(fireball:GetChildren()) do
		if particle:IsA("ParticleEmitter") then
			particle.Enabled = true
		end
	end
	
	local sound = sounds:WaitForChild(skillName):Clone()
	sound.Parent = fireball
	sound:Play()
	
	if raycastResult then
		
		local distance = raycastResult.Distance
		local speed = 0.2
		local tweenTime = speed * distance / 15
		
		local fireballTween = ts:Create(fireball, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Position = raycastResult.Position})
		fireballTween:Play()
		
		fireballTween.Completed:Connect(function()
			
			local sound = sounds:WaitForChild("Fireball_Explosion"):Clone()
			sound.Parent = fireball
			sound:Play()
			
			combatModule.Debris(character, fireball.Position, 20, 5, Vector3.new(math.random(1,1.15), math.random(1,1.5), math.random(1,1.15)), 3, false, "Fire")
			rs:WaitForChild("Events"):WaitForChild("ShakeCamera"):FireAllClients(500, 0.2)
			
			ts:Create(fireball:WaitForChild("PointLight"), TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Brightness = 0}):Play()
			ts:Create(fireball, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = fireball.Size + Vector3.new(2,2,2), Transparency = 1}):Play()
			
			for i, v in pairs(fireball:GetChildren()) do
				if v:IsA("ParticleEmitter") then
					v.Enabled = false
				end
			end
			for i, v in pairs(fireball:WaitForChild("Explosion"):GetChildren()) do
				if v:IsA("ParticleEmitter") then
					v:Emit(100)
				end
			end
			
			task.spawn(function()
				wait(2)
				fireball:Destroy()
			end)
			
		end)
		
	else
		warn("No collision detected.")
	end
	
end