I’m making a gun thing, but when it creates a part it’s supposed to do damage, but it doesn’t with no errors.
Local Script (gun):
local Gui = script.Parent:WaitForChild("ScreenGui")
local Ammo = 4
local WaitTime = 1
local StoredAmmo = 3
local ShootPart = script.Parent.ShootPart
local mouse = game.Players.localPlayer:GetMouse()
script.Parent.Parent.Equipped:Connect(function(Mouse)
animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
GuiClone = Gui:Clone()
GuiClone.Parent = game:GetService("Players").LocalPlayer.PlayerGui
animation:Play()
animation.Looped = true
end)
script.Parent.Parent.Activated:Connect(function(Mouse)
animation2 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
GuiClone.Frame.TextLabel.Text = Ammo.."|"..StoredAmmo
GuiClone.Enabled = true
script.Parent.Sound:Play()
ammoCheck()
Ammo = Ammo - 1
shoot()
animation2:Play()
wait(WaitTime)
end)
script.Parent.Parent.Unequipped:Connect(function()
animation:Stop()
animation.Looped = false
GuiClone.Enabled = false
end)
function reload()
StoredAmmo = StoredAmmo - 1
Ammo = 4
animation3 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation3)
animation3:Play()
if StoredAmmo < 1 then
GuiClone.Frame.TextLabel.Text = "No more ammo"
wait(1.5)
animation:Stop()
animation2:Stop()
GuiClone:Destroy()
script.Parent.Parent:Destroy()
end
end
function ammoCheck()
if Ammo < 1 then
reload()
end
end
function shoot()
local Bullet = Instance.new("Part", workspace)
Bullet.Size = Vector3.new(0.3, 0.05, 0.1)
Bullet.BrickColor = BrickColor.new("New Yeller")
Bullet.Material = Enum.Material.Neon
Bullet.Position = ShootPart.Position
Bullet.Name = "Bullet"
local Force = Instance.new("BodyVelocity")
for count = 1,2 do
Bullet.CFrame = CFrame.new(mouse.hit.p) + Vector3.new(0,1,0)
end
wait(2)
Bullet:Destroy()
end
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
reload()
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Script (part):
local Brick = game.Workspace:WaitForChild("Bullet")
local function PlayerTouched(hit)
local Parent = hit.Parent
if hit.Parent:FindFirstChild("Humanoid") then
Parent.Humanoid.Health = Parent.Humanoid.Health - 10
end
end
Brick.Touched:connect(PlayerTouched)