In my game, I want to have a weapon in my game that when clicked, shoots a bullet that damages (fair enough), however, when I shoot a player or NPC, there are “blind spots”, the NPC will not be hurt whatsoever even though the bullet clearly touched the humanoid. I have tried looking on the developer forum but have not found a good solution.
You can see the large trail of bullets go to the NPC, but when they connect it only dealt a bit of damage instead of mowing down the humanoid.
script when button is held down:
gun.Equipped:Connect(function(mouse)
equipted = true
player.PlayerGui.HUD.Ammo.Visible = true
updateammo()
mouse.Button1Down:Connect(function()
shooting = true
while shooting do
if gun.Ammo.Value > 0 then
wait()
remoteevent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.Position)
gunshot:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
else
empty:Play()
end
end
end)
mouse.Button1Up:Connect(function()
shooting = false
end)
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
end)
Script when bullet is created:
local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("ShotEvent2")
local serverstorage = game:GetService('ServerStorage')
remoteevent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
--print(gunPos)
--print(mosPos)
local bullet = Instance.new("Part")
bullet.Name = "Bullet"
bullet.Parent = game.Workspace
bullet.Position = gunPos
bullet.Shape = Enum.PartType.Cylinder
bullet.Size = Vector3.new(0.5, 0.25, 0.5)
--bullet.Size = Vector3.new(1,1,1)
--bullet.CanCollide = false
bullet.BrickColor = BrickColor.new("Gold")
local damagescript = serverstorage:FindFirstChild("Damage2"):Clone()
damagescript.Parent = bullet
local attacker = Instance.new("StringValue")
attacker.Name = "Attacker"
attacker.Parent = bullet
attacker.Value = player.Name
local distance = (mosPos - gunPos).magnitude
local speed = 999
bullet.CFrame = CFrame.new(gunPos, mosPos)
bullet.Velocity = bullet.CFrame.LookVector * speed
bullet.Orientation = gunOr + Vector3.new(0, -90, 0)
print(speed)
game:GetService("Debris"):AddItem(bullet, 2)
end)
Damage2 (damaging script:
local bullet = script.Parent
local hitsound = game.Workspace.Click
local headshot = game.Workspace.Headshot
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
if otherPart.Name == "Head" then
humanoid:TakeDamage(20)
headshot:Play()
else
humanoid:TakeDamage(10)
hitsound:Play()
end
--print("bullet connected")
local player = game.Players:FindFirstChild(humanoid.Parent.Name)
if player then
local tag = player:FindFirstChild("Killer")
if tag then
tag.Value = bullet.Attacker.Value
bullet:Destroy()
end
end
end
end
bullet.Touched:Connect(player_check)
Thank you for reading