Hello, I am using a free model gun script for a game but i want to edit some things to make it a bit better.
Needed help with:
Adding gun shot sounds
Adding a reload function.
Script:
script.Parent.Shoot.OnServerEvent:Connect(function(player,LookAt)
local Gun = player.Backpack:FindFirstChild(“Gun”) or player.Character:FindFirstChild(“Gun”)–rename gun to the tool name
local cframe = Gun.Barrel.CFrame
local bullet = game.ReplicatedStorage.Bullet:Clone()–rename bullet to the name of your bullet if it is different
bullet.Parent = script.Parent
bullet.CFrame = cframe
bullet.Velocity = LookAt*1000 --change this number to what you want the speed of your bullet to go at
local fly = Instance.new(“BodyForce”,bullet)
fly.Force = Vector3.new(0,bullet:GetMass()*196.2,0)
game.Debris:AddItem(bullet,10)
wait()
bullet.Touched:Connect(function()
wait(0.25)
bullet:remove()
end)
end)
Localscript:
script.Parent.Activated:Connect(function()
local pos = script.Parent.Parent.Humanoid.TargetPoint
local LookAt = (pos - script.Parent.Parent.Head.Position).Unit
script.Parent.Shoot:FireServer(LookAt)
end)
Bullet/ Raycast script:local debounce = true
local timebetdamage = 1
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
if debounce == true then
debounce = false
hit.Parent.Humanoid:TakeDamage(50)
–change this number here to the amount of damage you’d like your bullet to do
wait(timebetdamage)
debounce = true
end
end
end)