Whenever I try to shoot at an object, it someone avoids it, otherwise it's fine. Here's the code.
Player = game:GetService("Players").LocalPlayer
Mouse = Player:GetMouse()
Gun = script.Parent
Equip = false
Gun.Unequipped:connect(function()
Equip = false
print("Not using pistol")
end)
Gun.Equipped:connect(function()
Mouse.Icon = "http://www.roblox.com/asset/?id=79658449"
Equip = true
print("Using pistols")
end)
Gun.Activated:connect(function()
if Equip == true then
--Raycasting
local BulletRayMatrix = Ray.new(Gun.Handle.CFrame.p, (Mouse.Hit.p).unit*500)
local part, position = workspace:FindPartOnRay(BulletRayMatrix, Player.Character, false, true) --Part, object that was hit
local Bullet = Instance.new("Part", workspace)
Bullet.BrickColor = BrickColor.new("Really yellow")
Bullet.Material = "Neon"
Bullet.Transparency = 0.5
Bullet.Anchored = true
Bullet.Locked = true
Bullet.CanCollide = false
local Distance = (Gun.Handle.CFrame.p - position).Magnitude
Bullet.Size = Vector3.new(0.3, 0.3, Distance)
Bullet.CFrame = CFrame.new(Gun.Handle.CFrame.p, position) * CFrame.new(0, 0, -Distance / 2)
--Damage
Bullet.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum ~= nil and hit.Parent.Name ~= Player.Name then
end
end)
--
game.Debris:AddItem(Bullet, 0.2)
--Raycasting
print("shooting")
else
return;
end
end)
Any soloutions for this? It's like when I shoot at it it shoots over the object I want to shoot at :(!

1 comment
When firing at nothing, sky or just infront of nothing it shoots normal and casts to where I want it. But when I fire at things that has humanoids it basically avoids it, it shoots above or in the side of it.