player = game.Players.LocalPlayer
Gun = script.Parent
Ammo = 8
mouse = player:GetMouse()
function shoot()
if Ammo > 0 then
local Bullet = Instance.new("Part", workspace)
game.Debris:AddItem(Bullet, 2)
Bullet.Shape = ("Ball")
Bullet.Size = Vector3.new(0.2,0.2,0.2)
Bullet.TopSurface = ("Smooth")
Bullet.BottomSurface = ("Smooth")
Bullet.BrickColor = BrickColor.new("Dark stone grey")
Bullet.CanCollide = false
Bullet.CFrame = Gun.Handle.CFrame
Bullet.CFrame = CFrame.new(Bullet.Position,mouse.hit.p)
local x = Instance.new("BodyVelocity", Bullet)
x.Velocity = Bullet.CFrame.lookVector * 90
x.maxForce = Vector3.new (math.huge,math.huge,math.huge)
end
end
Gun.Activated:connect(shoot)
✓ ANSWER ACCEPTED
How can I make this gun script ACTUALLY do damage?
1 answer
✓ Accepted answer
First you want to add a damage variable, for example; local Dmg = 12 . Now you want to add a Debounce variable, local TookDamage = false so that you don't spam damage.
Now we want to add a .Touched Event and maybe a :Destroy() event. So that when the bullet hit's something the bullet will get destroyed.
so for now it should look like this;
--Add this script on to yours some how
local dmg = 12
local TookDmg = false
Bullet.Touched:connect(function(Hit)
Bullet:Destroy() --Destroys the bullet and then function if there is a humanoid or not
if Hit.Parent:FindFirstChild("Humanoid") then
if not TookDmg then --If tookdmg = false which it is
Hit.Parent:FindFirstChild("Humanoid").Health = Hit.Parent:FindFirstChild("Humanoid") - dmg --Takes away dmg
TookDmg = true --Stops damaging the player
wait()
TookDmg = false --Is ready to do damage again
end
end
end)
Try adding this script on to yours, now you can do dmg :D.
If this helped then please accept answer :D
This discussion is preserved as it was. New answers, comments, and votes are closed.
