I have a gun system but the ray doesnt create when i shoot in the sky, I believe it doesnt create it because there is no Mouse.Hit which I use for ray Positioning, so How to I avoid this path, I have a range but it doesnt work when I try shooting out of the guns range aswell. How do I also make it stop when it hits something other than the gun handle and player.
Current Script:
ShootEvent.OnServerEvent:Connect(function(player, GunTool, startPos, endPos, damage, Range)
local direction = (endPos - GunTool.Handle.Position).Unit * Range
local raycast = game.Workspace:Raycast(startPos, direction)
print(raycast.Instance.Name, raycast.Instance.Parent.Name)
if raycast then
local model = raycast.Instance:FindFirstAncestorOfClass("Model")
if model and model:FindFirstChild("Humanoid") and model:FindFirstChild("HumanoidRootPart") and model.Name ~= player.Character.Name then
GunTool.Shoot:Play()
local humanoid = model.Humanoid
if humanoid then
if raycast.Instance.Name == "Head" then
humanoid.Health -= (damage * 1.8)
else
humanoid.Health -= damage
end
end
end
end
CreateVisualSingle(startPos, endPos)
end)