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

GUI text not updating even though in a while loop?

So I am making an FPS game and I made this screen that appears on the side of the screen showing the info about the gun. In this script it shows the name and the amount of ammo. However, after the ammo updates at the beginning as full, after I shoot the gun it won't update anymore. This problem occurs in line 9. Yes, I have tested if the value decreases every time I shoot and it does. The text just won't update after the first loop.

This is in a local script inside the GUI:

local ReplicatedStorage = game.ReplicatedStorage
local Player = game.Players.LocalPlayer
local PlayerBackpack = Player:WaitForChild("Backpack")

while script.Parent.Visible == true do
	if PlayerBackpack:FindFirstChildOfClass("Tool") then
		local Gun = PlayerBackpack:FindFirstChildOfClass("Tool")
		script.Parent.GunName.Text = Gun.Name
		script.Parent.Ammo.Text = "Ammo: "..Gun.CurrentAmmo.Value.."/"..Gun.MaxAmmo.Value
		if Gun.Reloading.Value == true then
			script.Parent.Loaded.Text = "Reloading..."
		else
			script.Parent.Loaded.Text = "Loaded"
		end
	end
	wait(0.00000000001)
end

Thanks!

1 answer

the time might be to short idk and you forgot to turn the numbers to strings

local ReplicatedStorage = game.ReplicatedStorage
local Player = game.Players.LocalPlayer
local PlayerBackpack = Player:WaitForChild("Backpack")

while script.Parent.Visible == true do
    if PlayerBackpack:FindFirstChildOfClass("Tool") then
        local Gun = PlayerBackpack:FindFirstChildOfClass("Tool")
        script.Parent.GunName.Text = Gun.Name
        script.Parent.Ammo.Text = "Ammo: "..tostring(Gun.CurrentAmmo.Value).."/"..tostring(Gun.MaxAmmo.Value)
        if Gun.Reloading.Value == true then
            script.Parent.Loaded.Text = "Reloading..."
        else
            script.Parent.Loaded.Text = "Loaded"
        end
    end
    wait(0.1)
end

2 comments

0

the script still doesn't work

0

you don't need to convert the numbers to strings, it will automatically convert to a string only if you connect it to another string

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