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

invalid 'for' limit (number expected, got nil)?

Hello.Yes, its me again. I am trying to make one of those popular "Difficulty Chart Obbies." So here, i am playing with stage saving and completition. What i am trying to do is when a player joins the game all his data gets loaded and the completed stages turn green only for his client. However, this error is preventing me to do that. I have tried using delays, pcalls, if statements and still nothing.This error is really getting me annoyed :(. I am using remote events because as i expect it would fire to the client and not confuse other players.

Remote event definer script (Located is starterPlayerScripts):

game.ReplicatedStorage.PadColorChange.OnClientEvent:Connect(function(plr, StagesValue)
	print("started")
	local BeatenStages = {}
	if StagesValue == 1 then
		game.Workspace[1].BrickColor = BrickColor.new("Lime green")
	end
	local success, errormsg = pcall(function()
	for i = 1,StagesValue do --Line error
		table.insert(BeatenStages, i)
		print("Inserted "..tostring(i))
		end
	end)
	
	if success then
	for _, v in pairs(BeatenStages) do
		for _, m in pairs(game.Workspace:GetChildren()) do
			if m.Name == tostring(v) and m:IsA("Part") then
				m.BrickColor = BrickColor.new("Lime green")
				print("Color Changed")
			end
		end
		end
	else
		warn("Error: "..errormsg)
	end
end)

And where i pass the parameters (Its just a fragment of code but i am sure you will understand):

	if Data["Stage"] and Data["Level"] then
			Stage.Value = Data["Stage"]
			Level.Value = Data["Level"]
			print(Stage.Value)
			print("Loaded "..PlayerKey.." key successfully!")
			wait(1)
			game.ReplicatedStorage.PadColorChange:FireClient(Player, Stage.Value)

Thanks. If you need more information ask.

1 answer

✓ Accepted answer

OnClientEvent doesn't have a player parameter as you can see here, you can just use LocalPlayer since it's a Local Script. Basically what's happening is that your 'plr' parameter on the OnClientEvent is actually being assigned to Stage.Value, which means your 'StagesValue' parameter will remain nil. To fix this, just remove 'plr' from the OnClientEvent.

1 comment

0

Oh thanks, didn't knew it.

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