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

GUI text not updating even though in a while loop?

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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
0
the script still doesn't work MarcTheRubixQb 153 — 2y
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 T3_MasterGamer 2189 — 2y
Ad

Answer this question