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
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.
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.