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

How to make a High Score Board?

Asked by 10 years ago

Hey,

I have found a script for High Score board but it looks like not working, So i made some small changes but still not working.. What does i wrong i cannot found it (It says that there are no "Errors" Non blue lines..

This script going into "ServerScriptService" The "game.Workspace.HighScore.TopBlock.SurfaceGui" is correct into my workspace, Model: HighScore into this: TopBlock into that: SurfaceGui into SurfaceGui: Name1 - Name10 and Score1 - Score10

local ods = game:GetService("DataStoreService"):GetOrderedDataStore("Scores")
function updateBoard(board, data)
    for k,v in pairs(data) do
        local pos = k
        local name = v.key
        local score = v.value
        local dispname = board:findFirstChild("Name"..pos)
        local dispval = board:findFirstChild("Score"..pos)
        dispname.Text = tostring(name)
        dispval.Text = tostring(score)
    end 
end

while true do
    wait(60) -- Updates every 2 minutes
    local pages = ods:GetSortedAsync(false, 10)
    local data = pages:GetCurrentPage()
    updateBoard(game.Workspace.HighScore.TopBlock.SurfaceGui, data) -- change 'game.Workspace.HighScore.TopBlock.SurfaceGui'
end

This script going into "StarterGui" or "Players" --> Its a local script

wait(5)
local player = game.Players.LocalPlayer
while true do
game.Workspace.UploadScore:InvokeServer()
wait(60)-- How long you want to usend
end

This script going into "Workspace" into this script a have a "RemoteFunction" Named: UploadScore

function script.UploadScore.OnServerInvoke(player)
local inv = player:WaitForChild("leaderstats") -- Whatever stats
local score = game:GetService("DataStoreService"):GetOrderedDataStore("TopScores") -- Name of Data Store
score:SetAsync(player.Name, inv:FindFirstChild("Candy").Value) -- What is in the leaderstats
end

Thank you.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I realize this was 3 years ago, but in case anyone stumbles upon it, the answer is that in the StarterGui script the following line:

game.Workspace.UploadScore:InvokeServer()

should be:

game.workspace.Script.UploadScore:InvokeServer()

This is because this user places the remotefunction inside the script created in workspace so the localscript in StarterGui was unable to locate it. The "Script" part of the line should be replaced with whatever you named the script you placed in workspace.

Ad

Answer this question