Visualizing ray keeps falling down

Hello, after doing a lot of reserarch I couldn’t find a way to this. I’m making a projectile, but when ever I try to raycast it just “goes down” and doesn’t move to the the end position of the ray. How can I fix this?
Here’s my script so far:

local ProjectileEvent = game:GetService("ReplicatedStorage").ProjectileFolder:WaitForChild("ProjectileEvent")

ProjectileEvent.OnServerEvent:Connect(function(player)
	local Character = player.Character

	local function CreateBeam(origin, direction)
		local Projectile = Instance.new("Part")
		Projectile.Parent = workspace
		Projectile.Name = "Projecitle"
		Projectile.Position = Character.Direction.Position
		Projectile.Size = Vector3.new(2,2,2)
		Projectile.Shape = Enum.PartType.Ball
		Projectile.Material = Enum.Material.Neon
		Projectile.CanCollide = false
		Projectile:SetNetworkOwner(player)
	end
	
	local RayOrigin = Character.Direction.Position
	local RayDirection = Character.HumanoidRootPart.CFrame.LookVector * 50

	local rayParams = RaycastParams.new()
	rayParams.FilterDescendantsInstances = {Character}
	rayParams.FilterType = Enum.RaycastFilterType.Blacklist

	local rayResult = workspace:Raycast(RayOrigin, RayDirection, rayParams)	
	
	if rayResult then
		local hitPart = rayResult.Instance
			
		if hitPart.Parent:FindFirstChild("Humanoid") then
			hitPart.Parent.Humanoid:TakeDamage(10)
		end
	end
	CreateBeam(RayOrigin,RayDirection)
end)

I dont see Character being referenced anywhere.

My bad I added it now. I must’ve accidently deleted it.

It seems you dont use any of the arguments passed through CreateBeam() so it’s just creating the part at the starting point and nothing else.

To make the part move, you need to move it into the direction provided, with something like a BodyVelocity object or TweenService, whichever you prefer.

1 Like