just as like the title said, heres the local script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ReloadAnim
local ReloadTrack = nil
local tool = script.Parent
local handle = tool:FindFirstChild(“Handle”)
local larrel = handle and handle:FindFirstChild(“larrel”)
local debounce = false
local ammo = 34
local maxAmmo = 34
local reloading = false
– Reload
local function reload ()
if reloading == false then
reloading = true
if ReloadTrack then
ReloadTrack:Play()
end
local part = Instance.new("Part")
part.Position = tool.Handle.Position
part.Size = Vector3.new(0.201, 0.776, 0.32)
part.CFrame = tool.Handle.CFrame * CFrame.Angles(0, math.rad(90), 0)
part.Parent = workspace
part.CanCollide = true
part.BrickColor = BrickColor.new("Smoky grey")
part.Material = Enum.Material.Metal
script.Parent.Handle["Gun Reload"]:Play()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
task.wait(3)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
ammo = maxAmmo
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Text = ""..ammo.."/"..maxAmmo
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Transparency = 0
if ReloadTrack then
ReloadTrack:Stop()
end
reloading = false
wait(4)
part:Destroy()
end
end
– Shooting
tool.Activated:Connect(function()
if debounce == false and ammo > 0 and reloading == false then
debounce = true
ammo -= 1
tool.Shoot:FireServer(mouse.Hit.Position)
script.Parent.Handle.Barrel["Gun shot"]:Play()
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(2),0,0)
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Text = ""..ammo.."/"..maxAmmo
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Transparency = 0
task.wait(0.1)
debounce = false
elseif ammo <= 0 and reloading == false then
reload()
end
end)
– Equip Function
tool.Equipped:Connect(function()
end)
– Unequip Function
tool.Unequipped:Connect(function()
end
end)
heres the server script
local tool = script.Parent
local rep = game.ReplicatedStorage
local bulletline = rep.bullet
local bulletlinecloe = bulletline:Clone()
local animation = script.headhot
– Raycast Function
script.Parent.Shoot.OnServerEvent:Connect(function(player, mousePosition)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local raycastResult = workspace:Raycast(tool.Handle.Barrel.Position, (mousePosition - tool.Handle.Barrel.Position).Unit * 42, raycastParams)
while raycastResult and raycastResult.Instance:IsA("Accessory") do
raycastResult = workspace:Raycast(raycastResult.Position, (mousePosition - raycastResult.Position).Unit * 42, raycastParams)
end
if raycastResult then
local raycastInstance = raycastResult.Instance
local model = raycastInstance:FindFirstAncestorOfClass("Model")
local wood = raycastInstance.Material == Enum.Material.Wood
local metal = raycastInstance.Material == Enum.Material.Metal
local smooth = raycastInstance.Material == Enum.Material.SmoothPlastic
local humanoid = model and model:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if raycastInstance.Name == "Head" then
local anmier = model:FindFirstChild("Humanoid"):WaitForChild("Animator")
local play = anmier:LoadAnimation(animation)
humanoid:TakeDamage(56)
play:Play()
script.Parent.Handle.hit:Play()
local ind = Instance.new("Part")
ind.Parent = workspace
ind.CFrame = CFrame.new(raycastResult.Position)
ind.Size = Vector3.new(1.158, 0.45, 0.979)
ind.Material = Enum.Material.Ground
ind.BrickColor = BrickColor.new("Nougat")
ind.CanCollide = false
ind.Anchored = false
ind.Transparency = 1
local partiec = Instance.new("ParticleEmitter", ind)
partiec.Rate = 100
partiec.Size = NumberSequence.new(1.0)
partiec:Emit(100)
partiec.Texture = "rbxassetid://5069294691"
partiec.Color = ColorSequence.new(Color3.fromRGB(85, 0, 0))
partiec.EmissionDirection = "Top"
partiec.Transparency = NumberSequence.new(0.3)
partiec.Rotation = NumberRange.new(3,3)
partiec.RotSpeed = NumberRange.new(2,2)
partiec.Lifetime = NumberRange.new(0.8,0.8)
partiec.Speed = NumberRange.new(8, 8)
partiec.RotSpeed = NumberRange.new(2, 2)
partiec.SpreadAngle = Vector2.new(100,100)
task.wait(0.3)
ind:Destroy()
partiec:Destroy()
else
humanoid:TakeDamage(36)
script.Parent.Handle.hit:Play()
local ind = Instance.new("Part")
ind.Parent = workspace
ind.CFrame = CFrame.new(raycastResult.Position)
ind.Size = Vector3.new(1.158, 0.45, 0.979)
ind.Material = Enum.Material.Ground
ind.BrickColor = BrickColor.new("Nougat")
ind.CanCollide = false
ind.Anchored = false
ind.Transparency = 1
local partiec = Instance.new("ParticleEmitter", ind)
partiec.Rate = 100
partiec.Size = NumberSequence.new(1.0)
partiec:Emit(100)
partiec.Texture = "rbxassetid://5069294691"
partiec.Lifetime = NumberRange.new(0.8,0.8)
partiec.Color = ColorSequence.new(Color3.fromRGB(85, 0, 0))
partiec.EmissionDirection = "Top"
partiec.Transparency = NumberSequence.new(0.3)
partiec.Rotation = NumberRange.new(3,3)
partiec.RotSpeed = NumberRange.new(2,2)
partiec.Speed = NumberRange.new(8, 8)
partiec.RotSpeed = NumberRange.new(2, 2)
partiec.SpreadAngle = Vector2.new(100,100)
task.wait(0.3)
ind:Destroy()
partiec:Destroy()
end
end
end
end)
script.Parent.Shoot.OnServerEvent:Connect(function(player, mousePosition)
script.Parent.Handle.larrel.SurfaceLight.Enabled = true
script.Parent.Handle.larrel.ParticleEmitter.Enabled = true
script.Parent.Handle.theslidle.Transparency = 1
script.Parent.Handle.theslidle2.Transparency = 0
local bulletlinecloe = bulletline:Clone()
bulletlinecloe.Position = tool.Handle.theslidle.Position
bulletlinecloe.Parent = workspace
bulletlinecloe.CFrame = tool.Handle.CFrame * CFrame.Angles(0, math.rad(180),0)
bulletlinecloe.CFrame = tool.Handle.CFrame * CFrame.new(0,0,-23)
wait(0.2)
bulletlinecloe:Destroy()
script.Parent.Handle.theslidle.Transparency = 0
script.Parent.Handle.theslidle2.Transparency = 1
script.Parent.Handle.larrel.SurfaceLight.Enabled = false
script.Parent.Handle.larrel.ParticleEmitter.Enabled = false
print(“it works”)
local part = Instance.new(“Part”)
part.Position = tool.Handle.theslidle.Position
part.Size = Vector3.new(0.052, 0.044, 0.17)
part.CFrame = tool.Handle.CFrame * CFrame.Angles(0, math.rad(90), 0)
part.Parent = workspace
part.CanCollide = true
part.BrickColor = BrickColor.new(“Bronze”)
part.Material = Enum.Material.Metal
wait(4)
part:Destroy()
end)
tool.Equipped:Connect(function()
end)
end)