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

How to get a score GUI to work?

Asked by 10 years ago

I am currently making a score GUI, and I need it to pull information from the leaderboard and change the text in the GUI. Here are the scripts I am using:

Leaderboard script in the workspace:

local statList = {
    "Score";
}

game:GetService("Players").PlayerAdded:connect(function(playerObject)
    local leaderStats = Instance.new("Model", playerObject)
    leaderStats.Name = "leaderstats"
    for index, value in pairs(statList) do
        local intValue = Instance.new("IntValue", leaderStats)
        intValue.Name = value
    end
end)

Script in the GUI:

while true do
script.Parent.Score.Frame.Text = Workspace.Leaderstats.Score.Value
end

2 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

Your problem is in the Gui script.

player = script.Parent.Parent.Parent.Name --Guessing the script is directly under ScreenGui due to line 4.
while true do
wait(1) --Don't want to crash your players
script.Parent.Score.Frame.TextBox.Text = player.leaderstats.Score.Value --It's "leaderstats". Lua is case sensitive. But does the Frame have a textlabel or something?
end

Line four may error out since there is no Text Property in frame.

0
It is a textbox. TheRings0fSaturn 28 — 10y
0
So wait, Frame is the name of the Textbox? Or is it supposed to be Frame.TextBox.Text? M39a9am3R 3210 — 10y
0
Frame.TextBox.Text TheRings0fSaturn 28 — 10y
Ad
Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

In your GUI script, you're attempting to find Leaderstats in Workspace. Leaderstats is found in the player, and it should be in all lowercase.

Also, your GUI script uses an infinite loop without any delays to update. Lua will attempt to run the block of code an infinite amount of times, and your script will crash. I recommend using the .Changed event.

Here's the fixed GUI code (make sure it's a LocalScript):

local player = game.Players.LocalPlayer
repeat wait() until player:FindFirstChild("leaderstats")
local gui = script.Parent.Score.Frame
player.leaderstats.Score.Changed:connect(function(val)
    gui.Text = val
end)

If "Frame" is actually a frame, you should replace it with a TextLabel, as Frame does not have a Text property.

Answer this question