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

GUI that shows what level you are on is not working with no errors?

Asked by 1 year ago

I have tried to create a level system with a gui that shows what level you are at but the gui part just wont work here is the script

local player = game.Players.LocalPlayer
local xp = 0
local level = 0
local xpneeded = 100
local levelsgui = script.Parent.Parent.Frame.Levels
local xpgui = script.Parent.Parent.Frame.xp
xpgui.Text = "xp: "..xp
levelsgui.Text = "level: "..level

workspace.Coin.ClickDetector.MouseClick:Connect(function()
    xp +=1
    if xp == xpneeded then
        xpneeded += 100
        level +=1
        player.leaderstats.Levels.Value +=1
    end
end)
xpgui.Text = "xp: "..xp
levelsgui.Text = "level: "..level

script.Parent.MouseButton1Click:Connect(function ()
    script.Parent.Parent:WaitForChild("Frame").Visible = not script.Parent.Parent:WaitForChild("Frame").Visible
end)

If you can help me thanks it sill be very appreciated^^

0
Put lines 18 and 19 in the mouseclick function so that the gui updates every click instead of only the first time the script runs. cmgtotalyawesome 1418 — 1y

2 answers

Log in to vote
0
Answered by 1 year ago

I know I left a comment but I figured I'd answer as well just to show you. While using a while true do loop like the user above me suggested would work, it isn't as simple as it could be and would slow down your game if it had a lot of scripts running. Instead what I would do is change the gui text inside of the MouseClick function that you already have set up. Currently you are only changing the GUI text once when the script runs, however if you put lines 18 and 19 inside of your function like below, it should work like you want it:

local player = game.Players.LocalPlayer
local xp = 0
local level = 0
local xpneeded = 100
local levelsgui = script.Parent.Parent.Frame.Levels
local xpgui = script.Parent.Parent.Frame.xp
xpgui.Text = "xp: "..xp
levelsgui.Text = "level: "..level

workspace.Coin.ClickDetector.MouseClick:Connect(function()
    xp +=1
    if xp == xpneeded then
        xpneeded += 100
        level +=1
        player.leaderstats.Levels.Value +=1
    end
    xpgui.Text = "xp: "..xp
    levelsgui.Text = "level: "..level
end)


script.Parent.MouseButton1Click:Connect(function ()
    script.Parent.Parent:WaitForChild("Frame").Visible = not 
    script.Parent.Parent:WaitForChild("Frame").Visible
end)

Hope I helped!

Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

You need a while true do loop

the code is

local player = game.Players.LocalPlayer
local xp = 0
local level = 0
local xpneeded = 100
local levelsgui = script.Parent.Parent.Frame.Levels
local xpgui = script.Parent.Parent.Frame.xp
xpgui.Text = "xp: "..xp
levelsgui.Text = "level: "..level

script.Parent.MouseButton1Click:Connect(function ()
    script.Parent.Parent:WaitForChild("Frame").Visible = not script.Parent.Parent:WaitForChild("Frame").Visible
end)

workspace.Coin.ClickDetector.MouseClick:Connect(function()
    xp +=1
    if xp == xpneeded then
        xpneeded += 100
        level +=1
        player.leaderstats.Levels.Value +=1
    end
end)
while true do
    xpgui.Text = "xp: "..xp
    levelsgui.Text = "level: "..level

    wait(0.01)
end

Answer this question