Hello guys. Today I wanted to try and make a weapon model myself without taking it from toolbox using a gun script from a tutorial I watched. For some reason My gun doesn’t shoot, but my character holds it perfectly fine. The gun script is pretty old, probably from 2019. one gun that works are a union part, and one is a model with a mesh. I tried to make a “Barrel” part but it did not work. I don’t know what to do. Can anyone help me?
Photo of gun(MP5SD):
I also made the MP5SD a union part. Still doesn’t work.
local script inside weapon:
local gun = script.Parent
local gun_shot = gun.Handle['Gun Shot']
local empty_sound = gun.Handle.clip_empty
local reload_sound = gun.Handle.Reload
local player = game.Players.LocalPlayer
local clipSize = gun:WaitForChild('Ammo').Value
local ammo = gun:WaitForChild('Ammo')
local userInput = game:GetService('UserInputService')
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = 'rbxassetid://316279304'
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
gun.Equipped:Connect(function(mouse)
player.PlayerGui.ScreenGui.Ammo.Visible = true
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
remoteEvent:FireServer(gun.Handle.Position, mouse.Hit.p)
gun_shot:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
else
empty_sound:Play()
end
end)
end)
gun.Unequipped:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Visible = false
end)
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R then
if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 then
reload_sound:Play()
reload_sound.Ended:Wait()
if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)
gun.Ammo.Value = clipSize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
end
end
end
end
end
end)
ammo.Changed:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
end)
Bulletcreate inside serverscript service:
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
local ServerStorage = game:GetService('ServerStorage')
remoteEvent.OnServerEvent:Connect(function(player, gunPos, mosPos)
local bullet = Instance.new('Part')
bullet.Name = "Bullet"
bullet.Parent = game.Workspace
bullet.Shape = Enum.PartType.Block
bullet.Size = Vector3.new(0.25, 0.25, 0.25)
bullet.BrickColor = BrickColor.new('Gold')
local damageScript = ServerStorage:FindFirstChild('Damage'):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 = 850
bullet.CFrame = CFrame.new(gunPos, mosPos)
bullet.Velocity = bullet.CFrame.LookVector * speed
bullet.Orientation = Vector3.new(0, -90, 0)
wait(0.8)
bullet.Transparency = 1
bullet.CanCollide = false
end)
Damage script in Serverstorage:
local bullet = script.Parent
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
humanoid:TakeDamage(30)
end
end
bullet.Touched:Connect(player_check)
Also, forgot to mention the “ShotEvent” in ReplicatedStorage.