"Value = nil" but others eqaul a number

Im making a random code generater that generates whenever a player joins then fires the codes to the player which makes it unique to everyone. But when i print out the code on the server side it responds out with the full code of “1234” then fires the seperate values of 1, 2, 3, 4 to the client. Then I put the value to the text which works except for the first digit which makes the text say “nil” then i print the seperate codes by the client to see if it works but every number prints out except the first number (ex… server prints “3401” then client prints “4” “0” “1”) Its weird but its kind of the same type of script or something sooo please helP!!!

Players.playerepicnamexdlelrofl.PlayerGui.xd:120: attempt to concatenate number with nil is a error on the client side

server

game.Players.PlayerAdded:Connect(function(player)

local first = math.random(0,9)
local second = math.random(0,9)
local third = math.random(0,9)
local four = math.random(0,9)
local folder = game.Workspace.code	


local code = first .. second .. third .. four

    print(code)

	local epic = tostring(code)
	
	print(epic)





	game.ReplicatedStorage.RemoteEvents.CODE:FireClient(player, epic, first, second, third, four)
	
end)

client

game.ReplicatedStorage.RemoteEvents.CODE.OnClientEvent:Connect(function(player, epic, first, second, third, four)
	print("ok")
	
	local folder = game.Workspace.code
	
	folder.first.SurfaceGui.Text.Text = tostring(first)
	folder.second.SurfaceGui.Text.Text = tostring(second)
	folder.third.SurfaceGui.Text.Text = tostring(third)
	folder.four.SurfaceGui.Text.Text = tostring(four)
	
	print(first)
	print(second)
	print(third)
	print(four)
	local code = first .. second .. third .. four

	print(code .. " is " .. script.Parent.Parent.Name .. "'s code")
	
end)

(PS. i know i have a lot of random functions but i will remove them later (i just use them before as tests but forgot to delete them after i didnt need to use so)

1 Like

When you fire an event to a player, the “player” argument is dropped, so your client code should actually look like:

game.ReplicatedStorage.RemoteEvents.CODE.OnClientEvent:Connect(function(epic, first, second, third, four)
	print("ok")
	
	local folder = game.Workspace.code
	
	folder.first.SurfaceGui.Text.Text = tostring(first)
	folder.second.SurfaceGui.Text.Text = tostring(second)
	folder.third.SurfaceGui.Text.Text = tostring(third)
	folder.four.SurfaceGui.Text.Text = tostring(four)
	
	print(first)
	print(second)
	print(third)
	print(four)
	local code = first .. second .. third .. four

	print(code .. " is " .. script.Parent.Parent.Name .. "'s code")
	
end)
1 Like

oh wow i didnt guess 1 single line of code would fix it. Thanks!!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.