Hello So my gun works, but the trouble is that when I shot to the sky, the part doesn’t shows, like, part just doesn’t show, is not even added to Ignore_Model model, any idea why? Code:
local tool = script.Parent
repeat wait() until tool.Parent:FindFirstChildWhichIsA("Humanoid")
local Ammo = script.Parent.Ammo.Value
local StoredAmmo = script.Parent.StoredAmmo.Value
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local mouse = Player:GetMouse()
local Animations = script.Parent.Animations
local Equipped = false
local events = script.Parent.Events
local Character = Player.Character
local Spread = 12
local Camera = game.Workspace.CurrentCamera
local Ignore_Model = game.Workspace:FindFirstChild("Ignore_Model") or Instance.new("Model",game.Workspace)
Ignore_Model.Name = "Ignore_Model"
local Ray_Ignore = {Ignore_Model, Camera}
function equip()
local function retry(Animation)
Player.Character.Humanoid:LoadAnimation(Animations.HoldAnimation):Play()
end
local success, fail = pcall(function()
Player.Character.Humanoid:LoadAnimation(Animations.HoldAnimation):Play()
Equipped = true
end)
if success then
print("Successfull loaded animation")
elseif fail then
retry(Animations.HoldAnimation)
Equipped = true
end
end
function unequip()
for i,v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
Equipped = false
end
function Shot()
local Spread = CFrame.Angles(math.rad(math.random(-Spread, Spread)/10), math.rad(math.random(-Spread, Spread)/10), math.rad(math.random(-Spread, Spread)/10))
local Ray = Ray.new(Character.Head.Position, (CFrame.new(Character.Head.Position, mouse.Hit.Position ) * Spread).lookVector.unit * 6000)
local Hit,Pos = game.Workspace:FindPartOnRay(Ray, Character)
if Hit then
print("Part Touched")
events.Hit:FireServer(Hit)
print(Hit.Parent.Name)
end
local distance = (tool.BulletSpawn.CFrame.Position - Pos).magnitude
local Bullet = Instance.new("Part")
Bullet.Transparency = 0
Bullet.Anchored = true
Bullet.BrickColor = BrickColor.new("Ghost grey")
Bullet.CFrame = CFrame.new(Pos, tool.BulletSpawn.CFrame.Position) * CFrame.new(0, 0, -distance/2)
Bullet.Size = Vector3.new(0, 0, distance)
Bullet.Parent = workspace
Bullet.CanCollide = false
game:GetService("Debris"):AddItem(Bullet, 0.1)
end
tool.Equipped:Connect(function()
--equip()
tool.Activated:Connect(function()
Shot()
print("click")
end)
end)
Everything works, just the part doesnt shots when I aim to sky, or no hit parts.