Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make a ammo GUI showing how much ammo I got left in my pistol?

Asked by 7 years ago
Edited 7 years ago
Pistol Script: Ammo = 15

damage = 300

enabled = true

Player = game.Players.LocalPlayer
mouse = Player:GetMouse()


script.Parent.Activated:connect(function()
    if Ammo > 0 then
Bullet = Instance.new("Part", workspace)
game.Debris:AddItem(Bullet, 2)
Bullet.CFrame = script.Parent.Handle.CFrame
Bullet.CFrame = CFrame.new(Bullet.Position, mouse.Hit.p)
Bullet.Size = Vector3.new(0.2, 0.2, 0.2)
Bullet.Shape = "Ball"
Bullet.BrickColor = BrickColor.new("Really black")
Bullet.CanCollide = true
local Vel = Instance.new("BodyVelocity", Bullet)
Vel.Velocity = Bullet.CFrame.lookVector *80
Vel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
script.Parent.GripPos = Vector3.new(0, -0.5, -0.4)
wait(0)
script.Parent.GripPos = Vector3.new(0, -0.5, -0.45)
script.Parent.FireSound:Play()
Ammo = Ammo - 1
    end

wait(0)
Bullet.Touched:connect(function(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
    hit.Parent.Humanoid:TakeDamage(damage)

wait(1)
Bullet:Destroy()
if enabled == true then 
    enabled = false
enabled = true
wait(5)
enabled = false
wait(0)
end
end
end)
end)

mouse.KeyDown:connect(function(Key)
    if Key == "r" then  
if Ammo == 0 then
wait(1) 
script.Parent.ReloadSound:Play()
        Ammo = 15
end
end
end)

Anyways, instead of just not knowing how much ammo you have left. I would like to make a GUI, with numbervalues. Now, I can do that. But, when I shoot, the textlabel text stays at the original text (15)

Someone please help.

0
put it into a code block pluginfactory 463 — 7y
0
I forgot to add the code blocks sorry. Kraken_54 22 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

local textlabel = plr.PlayerGui.SCREENGUI_NAME.TEXTLABEL_NAME

if Ammo > 0 then
13
Bullet = Instance.new("Part", workspace)
14
game.Debris:AddItem(Bullet, 2)
15
Bullet.CFrame = script.Parent.Handle.CFrame
16
Bullet.CFrame = CFrame.new(Bullet.Position, mouse.Hit.p)
17
Bullet.Size = Vector3.new(0.2, 0.2, 0.2)
18
Bullet.Shape = "Ball"
19
Bullet.BrickColor = BrickColor.new("Really black")
20
Bullet.CanCollide = true
21
local Vel = Instance.new("BodyVelocity", Bullet)
22
Vel.Velocity = Bullet.CFrame.lookVector *80
23
Vel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
24
script.Parent.GripPos = Vector3.new(0, -0.5, -0.4)
25
wait(0)
26
script.Parent.GripPos = Vector3.new(0, -0.5, -0.45)
27
script.Parent.FireSound:Play()
28
Ammo = Ammo - 1
textlabel.Text = Ammo
    end


Ignore the numbers. those are just you lines all you have to do is make a screengui with a textlabel and add that line evreytime you shoot.

1
There's a button you press to copy code when hovering over a code block. OldPalHappy 1477 — 7y
1
That doesn't work @johndeer2233 Kraken_54 22 — 7y
Ad

Answer this question