Need help with this error i can't seem to understand to fix

someone made me this code

for a board to update stats whenever a player gets a kill or other form of stats.

it’s giving me this error code saying
“attempt to concatenate string with nil”

also it’s never done this before so i don’t understand?
someone made it for me years ago.
could it need an update?

local Part = script.Func
Part.Parent = workspace

wait(5)

local Key = workspace._DataStoreKey
local DS_Wins = “ds_wins”… Key.Value
local DS_Spree = “ds_spree”… Key.Value
local DS_Other = “ds_other”… Key.Value

local Players = game.Players

local Gui = Part.SurfaceGui
local List = Gui.ScrollingFrame
local Page = Gui.Page

local ReplicatedStorage = game.ReplicatedStorage

local function LoadPage(Player)
local Bust = ReplicatedStorage.LocalBoardRemotes.GetBust:InvokeServer(Player.UserId)
Page.ImageLabel.Image = Bust

--local SavedWins = DS_Wins:GetAsync(Player.UserId)
local SavedWins = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Wins, Player.UserId)
Page.HighestWins.Text = "Highest Wins: ".. SavedWins

--local SavedSpree = DS_Spree:GetAsync(Player.UserId)
local SavedSpree = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Spree, Player.UserId)
Page.HighestSpree.Text = "Highest Spree: ".. SavedSpree

--local SavedOther = DS_Other:GetAsync(Player.UserId)
local SavedOther = ReplicatedStorage.LocalBoardRemotes.GetData:InvokeServer(DS_Other, Player.UserId)
Page.TotalWins.Text = "Total Wins: ".. SavedOther[2]
Page.Deaths.Text = "Deaths: ".. SavedOther[3]
Page.KDR.Text = "KDR: ".. SavedOther[2]/SavedOther[3] 

if SavedOther[4] then 
	
	Page.ArenaWins.Text = "Arena Wins: ".. SavedOther[4] --no more error 
	
end 

Page.ImageLabel.name.Text = Player.Name
Page.ImageLabel.Tier.Text = "Tier ".. ((math.floor(SavedOther[2] / 200)) + 1) -- Every Tier = 200 total wins

end

local function Update()
for _,v in pairs(List:GetChildren()) do
if v:IsA(“TextButton”) then
v:Destroy()
end
end

for _,v in pairs(Players:GetChildren()) do
	local Button = script.TextButton:Clone()
	Button.Text = v.Name
	Button.Parent = List
	
	Button.MouseButton1Down:Connect(function()
		LoadPage(v)
		Page.Visible = true
	end)
end

end

Players.PlayerAdded:Connect(function() wait(1) Update() end)
Players.PlayerRemoving:Connect(function() wait(1) Update() end)

wait(3)

Update()

your formatting is messed up but it seems like the ReplicatedStorage.LocalBoardRemotes.GetOrdered remote function is returning nil. We would need to see what that function does to help.

1 Like

i have no idea i didn’t make it. my friend did. but
i think the point of that code is to where it’s trying to update or change the value of the text of “highest spree” same with wins and something is going nil when it’s updating or? i don’t get it

--local SavedSpree = DS_Spree:GetAsync(Player.UserId)
local SavedSpree = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Spree, Player.UserId)
	
	Page.HighestSpree.Text = "Highest Spree: ".. SavedSpree

ctrl shift f to search every script for GetOrdered, you need to find the function the server attached to this RemoteFunction. Look for OnServerInvoke =

also ran some tests and found out that error pops up when i click on the board to update or to show the stats basically. so i don’t know

ok i will now, is this what you’re talking about.

local ReplicatedStorage = game.ReplicatedStorage

local Remotes = ReplicatedStorage.LocalBoardRemotes

local GetBust = Remotes.GetBust

local Players = game.Players

local GetData = Remotes.GetData

local GetOrdered = Remotes.GetOrdered

GetData.OnServerInvoke = function(Player, DataStoreName, UserId)

local DataStore = game:GetService(“DataStoreService”):GetDataStore(DataStoreName)

return DataStore:GetAsync(UserId)

end

GetOrdered.OnServerInvoke = function(Player, DataStoreName, UserId)

local DataStore = game:GetService(“DataStoreService”):GetOrderedDataStore(DataStoreName)

return DataStore:GetAsync(UserId)

end

GetBust.OnServerInvoke = function(Player, UserId)

return Players:GetUserThumbnailAsync(UserId, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)

end

GetOrdered.OnServerInvoke = function(Player, DataStoreName, UserId)
   local DataStore = game:GetService(“DataStoreService”):GetOrderedDataStore(DataStoreName)
   return DataStore:GetAsync(UserId)
end

Yeah this can return nil, especially if there is no data in the datastore. The most minimal fix would be to add a default value like so

   return DataStore:GetAsync(UserId) or 0

it said attempt to index number with number? error

Please provide the script giving that error, and it would be helpful if you could add a comment noting which line the error comes from. My example should not result in that error.

the script that is giving the error is what i shared already.

how can i share a code on the forums correctly? i’m new to it

pasting code between three ticks ``` will format it in a nice colorful block

```
local function pasted_code(param1, param2)
print(“my code with indentation”)
end
```

will look like this →

local function pasted_code(param1, param2)
    print("my code with indentation")
end


local Part = script.Func
Part.Parent = workspace

wait(1)

local Key = workspace._DataStoreKey
local DS_Wins	= "ds_wins".. Key.Value
local DS_Spree	= "ds_spree".. Key.Value
local DS_Other	= "ds_other".. Key.Value

local Players = game.Players

local Gui = Part.SurfaceGui
local List = Gui.ScrollingFrame
local Page = Gui.Page

local ReplicatedStorage = game.ReplicatedStorage

local function LoadPage(Player)
	local Bust = ReplicatedStorage.LocalBoardRemotes.GetBust:InvokeServer(Player.UserId)
	Page.ImageLabel.Image = Bust

	--local SavedWins = DS_Wins:GetAsync(Player.UserId)
	local SavedWins = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Wins, Player.UserId)
	
	Page.HighestWins.Text = "Highest Wins: ".. SavedWins

	--local SavedSpree = DS_Spree:GetAsync(Player.UserId)
	local SavedSpree = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Spree, Player.UserId)
		
		Page.HighestSpree.Text = "Highest Spree: ".. SavedSpree

	--local SavedOther = DS_Other:GetAsync(Player.UserId)
	local SavedOther = ReplicatedStorage.LocalBoardRemotes.GetData:InvokeServer(DS_Other, Player.UserId)
	Page.TotalWins.Text = "Total Wins: ".. SavedOther[2]
	Page.Deaths.Text = "Deaths: ".. SavedOther[3]
	Page.KDR.Text = "KDR: ".. SavedOther[2]/SavedOther[3] 

	if SavedOther[4] then 

		Page.ArenaWins.Text = "Arena Wins: ".. SavedOther[4] --no more error 

	end 

	Page.ImageLabel.name.Text = Player.Name
	Page.ImageLabel.Tier.Text = "Tier ".. ((math.floor(SavedOther[2] / 200)) + 1) -- Every Tier = 200 total wins
end

local function Update()
	for _,v in pairs(List:GetChildren()) do
		if v:IsA("TextButton") then
			v:Destroy()
		end
	end

	for _,v in pairs(Players:GetChildren()) do
		local Button = script.TextButton:Clone()
		Button.Text = v.Name
		Button.Parent = List

				Button.MouseButton1Down:Connect(function()
					
			LoadPage(v)
			Page.Visible = true
		end)
		end
end

Players.PlayerAdded:Connect(function() wait(1) Update() end)
Players.PlayerRemoving:Connect(function() wait(1) Update() end)

wait(1)

	Update()
		

So you need different defaults for each value in your board script. It will be better to put the or at the call site instead, remove my last example and try this for the board script.

local SavedWins = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Wins, Player.UserId) or 0
Page.HighestWins.Text = "Highest Wins: ".. SavedWins

--local SavedSpree = DS_Spree:GetAsync(Player.UserId)
local SavedSpree = ReplicatedStorage.LocalBoardRemotes.GetOrdered:InvokeServer(DS_Spree, Player.UserId) or 0
Page.HighestSpree.Text = "Highest Spree: ".. SavedSpree

--local SavedOther = DS_Other:GetAsync(Player.UserId)
local SavedOther = ReplicatedStorage.LocalBoardRemotes.GetData:InvokeServer(DS_Other, Player.UserId) or {0,0,0}
Page.TotalWins.Text = "Total Wins: ".. SavedOther[2]
Page.Deaths.Text = "Deaths: ".. SavedOther[3]
Page.KDR.Text = "KDR: ".. SavedOther[2]/SavedOther[3] 
1 Like

Nice job formatting! I would also recommend always have roblox format your code, regularly click this button
image
“Format Document” will correct indentation

thank you so much. and thank you for teaching me all this information in general. thank you very much this helped so much i’m so glad lol i knew it had something to do with the board code in that line of code area i just couldn’t do it all i knew was it had something to do with the number or something causing it to go nil but i couldn’t find it

um some reason the player stats aren’t updating to what the leaderstats are? can you please help? and thank you for that i never noticed that at all lol

This block of code leads me to believe you want this to continually update.

while task.wait(1) do
    Update()
end

This will always update every second. The problem is that your code will invoke the server 3 times per player every second. It would be best to convert this board script to the server side, that way the clients aren’t all constantly using remote events and roblox can handle the replication faster. You would largely be replacing the Invoke Server calls with leaderstats references instead.

man i can’t do that solution the second thing you said. i can’t fix that problem with the code it isn’t mine it was made by one of my old friends from years ago. it was working fine before so i’m now needing help to fix

1 Like