Hello im have problem with bullet hole.
robloxapp-20210417-2133489.wmv
The fact is that when I shoot, the hole appears at the mouse position, and not where Ray hit. Im don’t know how to fix this.
Server script:
tool.Fire.OnServerEvent:Connect(function(player, mouseHit, rate)
if script.Parent.CanFire.Value == false then
script.Parent.CanFire.Value = true
Ammo.Value = Ammo.Value - 1
local fires = tool.Handle.Fire:Clone()
fires.Parent = tool.Handle
fires:Play()
local ray = Ray.new(tool.Handle.GunFirePoint.WorldCFrame.p, (mouseHit.p - tool.Handle.GunFirePoint.WorldCFrame.p).unit * 300)
local hit, position, normal = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
local distance = (position - tool.Handle.GunFirePoint.WorldCFrame.p).magnitude
local part = Instance.new("Part")
part.Name = "Bullet"
part.Anchored = true
part.CanCollide = false
part.Material = "Neon"
part.BrickColor = BrickColor.new("Gold")
part.Size = Vector3.new(0.1, 0.1, distance)
part.CFrame = CFrame.new(position, tool.Handle.GunFirePoint.WorldCFrame.p) * CFrame.new(0, 0, - distance / 2)
part.Parent = workspace
if hit and hit.Parent ~= workspace.BulletHoles then
if hit.Parent and hit.Parent ~= workspace.BulletHoles then
local hole = game.ReplicatedStorage.Metal:Clone()
hole.Name = "Bullet Hole"
hole.Parent = workspace.BulletHoles
hole.Position = mouseHit.p
hole.CFrame = CFrame.new(hole.Position, hole.Position + normal)
local weld = Instance.new("Weld")
weld.Part0, weld.Part1 = hit,hole
weld.C0 = hit.CFrame:Inverse()
weld.C1 = hole.CFrame:Inverse()
weld.Parent = hole
game:GetService("Debris"):AddItem(hole, 8)
if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "Head" then
hit.Parent.Humanoid:TakeDamage(math.random(137,168))
end
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(math.random(34,63))
elseif hit.Parent:FindFirstChild("Humanoid") and hit.Name == "Left Leg" or hit.Name == "Right Leg" then
hit.Parent.Humanoid:TakeDamage(math.random(23,45))
end
end
end
game:GetService("Debris"):AddItem(part, 0.03)
end
wait(rate)
script.Parent.CanFire.Value = false
end)
(Please make a script and explain the lines to me. I don’t know much programming)