Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this script work only on an empty baseplate, but not in another game?

The coding seems correct, however it refuses to work in game, I tested it in a baseplate and it somehow worked but the scripts are exactly the same in both the baseplate and game.

This script is supposed to list the players points on a global leaderboard as a GUI.

local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("Points")
local Pages = ODS:GetSortedAsync(false,10)
local Data = Pages:GetCurrentPage()
local GUI = game.StarterGui.LeaderboardUI

game.Players.PlayerAdded:Connect(function(plr)
	local New = Instance.new("Folder")
	New.Name = "leaderstats"
	New.Parent = plr
	local Stage = Instance.new("NumberValue")
	Stage.Name = "Stage"
	Stage.Parent = New
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local Stage = plr.leaderstats.Points
	if Stage then
		ODS:IncrementAsync(plr.Name,Stage.Value)
	end
end)

local function Update()
	local succ,err = pcall(function()
		local Template = GUI.Template
			for i,v in pairs(GUI.MainFrame:GetChildren())do
				if v:IsA("Frame") then
					v:Destroy()
				end
			end
		for a,k in pairs(Data)do
			local PlayerName = k.key
			local PlayerStage = k.value
			local NewTemp = Template:Clone()
			NewTemp.Name = PlayerName
			NewTemp.FrameName.Text = PlayerName
			NewTemp.FrameValue.Text = PlayerStage
			NewTemp.Visible = true
			NewTemp.Parent = GUI.MainFrame
		end
	end)
	if err then
		warn("An error has occured when trying to update the leaderboard: " .. err)
	end
end

Update()

spawn(function()
	while wait(60*3) do
		Update()
	end
end)

What could be causing this? Please help!

2 comments

0

The server and client need to talk, add a remote event. You could also add a remote event and clone the script to the players backpack from PlayerGui

0

Wait() should NOT be a condition.

1 answer

Note there are two scripts here, local and server...This is assuming your GUI is in RS. This is an example of the remote needed for client/server communication for FE. This is in addition to your script obviously.

-- LocalScript 
local remote = game:GetService("ReplicatedStorage").YourGui -- name it


remote.OnClientEvent:Connect(function()
    script.Parent.Visible = true
end)

-- Server
local remote = game:GetService("ReplicatedStorage").YourGui

local function click(player) 
  remote:FireClient(player) -- fire to client
end 

script.Parent.ClickDetector.MouseClick:Connect(click)

This discussion is preserved as it was. New answers, comments, and votes are closed.