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

My leaderboard works in studio, but not on a live server. How do I fix?

I'm making a military themed game that has the ranks saved in the game code. and I have this leaderboard script:~~~~~~~~~~~~~~~~~

game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("StringValue")
stats.Name = "leaderstats"
stats.Parent = p

local rank = Instance.new("StringValue")
rank.Name = "Rank"
rank.Value = "REC"
local reg = Instance.new("StringValue")
reg.Name = "Regiment"
reg.Value = "No-Reg"

--ranks--

PVT = {}
LCPL = {}
CPL = {}
SGT = {}
SSGT = {}
WOC2 = {}
WOC1 = {}
LT = {}
CPT = {}
MAJ = {}
LTCOL = {}
COL = {}
BRIG = {}
MAJGEN = {}
LTGEN = {}
GEN = {}
FM = {"wexabite"}

--regiments--

RIFLES = {}
RGG = {}
SAS = {}
AAC = {}
PARAS = {}
ETS = {}

for i=1, #RIFLES do
	if RIFLES[i] == game.Players.LocalPlayer.Name then
		reg.Value = "RIFLES"
	end
end
for i=1, #RGG do
	if RGG[i] == game.Players.LocalPlayer.Name then
		reg.Value = "RGG"
	end
end
for i=1, #SAS do
	if SAS[i] == game.Players.LocalPlayer.Name then
		reg.Value = "SAS"
	end
end
for i=1, #AAC do
	if AAC[i] == game.Players.LocalPlayer.Name then
		reg.Value = "AAC"
	end
end
for i=1, #PARAS do
	if PARAS[i] == game.Players.LocalPlayer.Name then
		reg.Value = "PARAS"
	end
end
for i=1, #ETS do
	if ETS[i] == game.Players.LocalPlayer.Name then
		reg.Value = "ETS"
	end
end
for i=1, #PVT do
	if PVT[i] == game.Players.LocalPlayer.Name then
		rank.Value = "PVT"
	end
end
for i=1, #LCPL do
	if LCPL[i] == game.Players.LocalPlayer.Name then
		rank.Value = "LCPL"
	end
end
for i=1, #CPL do
	if CPL[i] == game.Players.LocalPlayer.Name then
		rank.Value = "CPL"
	end
end
for i=1, #SGT do
	if SGT[i] == game.Players.LocalPlayer.Name then
		rank.Value = "SGT"
	end
end
for i=1, #SSGT do
	if SSGT[i] == game.Players.LocalPlayer.Name then
		rank.Value = "SSGT"
	end
end
for i=1, #WOC2 do
	if WOC2[i] == game.Players.LocalPlayer.Name then
		rank.Value = "WOC2"
	end
end
for i=1, #WOC1 do
	if WOC1[i] == game.Players.LocalPlayer.Name then
		rank.Value = "WOC1"
	end
end
for i=1, #LT do
	if LT[i] == game.Players.LocalPlayer.Name then
		rank.Value = "LT"
	end
end
for i=1, #CPT do
	if CPT[i] == game.Players.LocalPlayer.Name then
		rank.Value = "CPT"
	end
end
for i=1, #MAJ do
	if MAJ[i] == game.Players.LocalPlayer.Name then
		rank.Value = "MAJ"
	end
end
for i=1, #LTCOL do
	if LTCOL[i] == game.Players.LocalPlayer.Name then
		rank.Value = "LTCOL"
	end
end
for i=1, #COL do
	if COL[i] == game.Players.LocalPlayer.Name then
		rank.Value = "COL"
	end
end
for i=1, #BRIG do
	if BRIG[i] == game.Players.LocalPlayer.Name then
		rank.Value = "BRIG"
	end
end
for i=1, #MAJGEN do
	if MAJGEN[i] == game.Players.LocalPlayer.Name then
		rank.Value = "MAJGEN"
	end
end
for i=1, #LTGEN do
	if LTGEN[i] == game.Players.LocalPlayer.Name then
		rank.Value = "LTGEN"
	end
end
for i=1, #GEN do
	if GEN[i] == game.Players.LocalPlayer.Name then
		rank.Value = "GEN"
	end
end
for i=1, #FM do
	if FM[i] == game.Players.LocalPlayer.Name then
		rank.Value = "FM"
	end
end
rank.Parent = stats
reg.Parent = stats
end)
The problem is: It works flawlessly in studio, but not in game :/ Any help? Am I doing something wrong?

2 answers

✓ Accepted answer

Edit: my previous solution did not work, but I tested this in studio and it should work now.

Firstly, this script is quite inefficient. You have over 100 lines that can be simplified.

Also, it's not meant to be a local script, as you can't create instances with them that will get replicated onto the server. In other words, you see new instances, others don't.

Put the following in a Script , not a LocalScript.

local ranks = {

    --ranks--

    PVT = {};
    LCPL = {};
    CPL = {};
    SGT = {};
    SSGT = {};
    WOC2 = {};
    WOC1 = {};
    LT = {};
    CPT = {};
    MAJ = {};
    LTCOL = {};
    COL = {};
    BRIG = {};
    MAJGEN = {};
    LTGEN = {};
    GEN = {};
    FM = {"wexabite"}

}

local regiments = {

    --regiments--

    RIFLES = {};
    RGG = {};
    SAS = {};
    AAC = {};
    PARAS = {};
    ETS = {};

}

game.Players.PlayerAdded:Connect(function(p)
    local stats = Instance.new("StringValue")
    stats.Name = "leaderstats"
    stats.Parent = p

    local rank = Instance.new("StringValue")
    rank.Name = "Rank"
    rank.Value = "REC"

    local reg = Instance.new("StringValue")
    reg.Name = "Regiment"
    reg.Value = "No-Reg"

    for name,ranking in pairs(ranks)do
        for _,v in pairs(ranking)do
            if p.Name == v then
                rank.Value = name
            end
        end
    end

    for name,regiment in pairs(regiments)do
        for _,v in pairs(regiment)do
            if p.Name == v then
                reg.Value = name
            end
        end
    end

	rank.Parent = stats
	reg.Parent = stats
end)

3 comments

0

Does not work. :/ I've tried putting this Script in Server storage and script service but this one doesn't even work in studio.

0

have you turned on studio access API on configure game/place

0

I have edited the script. It should work now.

You can use:

game.Players.PlayerAdded:Connect (function (player)
rank.Value = player:GetRoleInGroup()
end)

And then use this for the regiments:

--this should be in the above function
if player.IsInGroup(GROUPID) then
  regiment.Value = REGIMENT NAME

1 comment

0

The thing is... I don't have a group, that's why it saves in the game code. I want to know why it works in studio and not player

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