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)