Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Ammo gui isn't working on a gun, can somebody help me with what I've done wrong?

I got an ammo gui ed with a LocalScript but it aparently doesn't work :/

local players = game:GetService("Players")
local player = players.LocalPlayer
local weapon = .Parent
local ammo = .Parent:WaitForChild('CurrentAmmo').Value
local maxammo = .Parent:WaitForChild('MaxAmmo').Value

weapon.Equipped:connect(function()
	local gui = Instance.new('ScreenGui', player.PlayerGui)
	gui.Name = 'WeaponGui'
	local currentammogui = Instance.new('TextBox', gui)
	currentammogui.Name = 'CurrentAmmo'
	currentammogui.Text = 'Current: '..ammo
	currentammogui.Size = UDim2.new(0.17, 0, 0.07, 0)
	currentammogui.Position = UDim2.new(0.81, 0, 0.9, 0)
	currentammogui.BackgroundTransparency = 1
	currentammogui.FontSize = 'Size28'
	currentammogui.Font = 'Code'
	local maxammogui = Instance.new('TextBox', gui)
	maxammogui.Name = 'MaxAmmo'
	maxammogui.Text = 'Max: '..maxammo
	maxammogui.Size = UDim2.new(0.17, 0, 0.07, 0)
	maxammogui.Position = UDim2.new(0.81, 0, 0.85, 0)
	maxammogui.BackgroundTransparency = 1
	maxammogui.FontSize = 'Size28'
	maxammogui.Font = 'Code'
end)

ammo.Changed:connect(function(newammo)
	local currentammogui = player.PlayerGui.WeaponGui:WaitForChild('CurrentAmmo')
	currentammogui.Text = 'Current: '..newammo
end)

weapon.Unequipped:connect(function()
	player.PlayerGui.WeaponGui:Remove()
end)

Photo of how my Studio looks like: http://prntscr.com/e7is61

1 answer

When setting the initial text of currentammogui and the maxammogui, you need to index the ammo Value's Value Property.

--line 12
currentammogui.Text = 'Current: '..ammo.Value

--line 20
maxammogui.Text = 'Max: '..maxammo.Value

4 comments

0

It is, it just copied wrong somehow :/

0

I have a script to change the value, but it isn't this script :/

0

Alright, I think I found your error then. Edited my answer. Next time supply any errors that appear in the Output. Makes it super easy for us to fix your code.

0

That's not the problem as look correctly at the script is says script.Parent:WaitForChild('CurrentAmmo').Value

This discussion is preserved as it was. New answers, comments, and votes are closed.