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

Why doesn't the text changing work?

Asked by 7 years ago

I made a gui for my weapons to show their ammo & stuff, the ammo shows up, shows the right amount of ammo, but when I fire with my gun my currentammo doesn't change ;/

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

weapon.Equipped:connect(function()
    local gui = Instance.new('ScreenGui', player.PlayerGui)
    gui.Name = 'WeaponGui'
    local currentammogui = Instance.new('TextLabel', gui)
    currentammogui.Name = 'CurrentAmmo'
    currentammogui.Text = 'Current: '..ammo.Value
    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('TextLabel', gui)
    maxammogui.Name = 'MaxAmmo'
    maxammogui.Text = 'Max: '..maxammo.Value
    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)

Help me ;p

1 answer

Log in to vote
0
Answered by
j236 26
7 years ago
Edited 7 years ago

Use a while loop on the

currentammogui.Text = 'Current: '..ammo.Value

Like this

while wait(10) do
--script to change value
end

EDIT: READ ME

The function is asking to create a GUI inside the game.Players. There is no PlayerGui in the game.Players. There is one on each game.Player.LocalPlayer.

local gui = Instance.new('ScreenGui', player.LocalPlayer.PlayerGui)
gui.Name = 'WeaponGui'
0
EDIT: The function is wrong too! j236 26 — 7y
0
I used LocalPlayer ;p and there is another script that is chaging the value so it isn't done by this script. VladimVladim 78 — 7y
Ad

Answer this question