How to turn each index value in the same order into a string for text

  1. What do you want to achieve? I made a randomized code inside a local script and i wanted to share it to the server script with remote event. And then i want that table to split into 4 strings so i can use them for 4 Texts (each text 1 string).

  2. What is the issue? My code doesn’t work

Local Script

local PinCodeRandom  = {math.random(1,9), math.random(1,9),math.random(1,9),math.random(1,9)}
local PinCode = ""

for i, v in PinCodeRandom do
	PinCode = PinCode..tostring(v)
end

game.ReplicatedStorage.SharePinCode:FireServer(PinCodeRandom)
	print("hello")

Server Script

local PinCodeRandom = {}
local PinCode = ""

game.ReplicatedStorage.SharePinCode.OnServerEvent:Connect(function(Player, a)
	PinCodeRandom = a
	for i, v in PinCodeRandom do
		PinCode = PinCode..tostring(v)
	end
	print(PinCodeRandom)
	print(PinCode)
end)

local ShowCode1 = game.Workspace.ShowCode1.SurfaceGui.TextLabel
local ShowCode2 = game.Workspace.ShowCode2.SurfaceGui.TextLabel
local ShowCode3 = game.Workspace.ShowCode3.SurfaceGui.TextLabel
local ShowCode4 = game.Workspace.ShowCode4.SurfaceGui.TextLabel

ShowCode1.Text = tostring(PinCodeRandom[1])

Here’s what you’re doing:
Localscript:

  • Create table of 4 random numbers from 1-9
  • Create a 4 character string with the 4 random numbers in order
  • Sent the table to the serverscript

Script:

  • On server event, recreate the 4 character string
  • Print the table and 4 char string
  • Change textlabel text to the first number in the table

Is this meant to be a checksum or something? I don’t see any problems with the code and your intentions are unclear

the ShowCode1.Text = tostring(PinCodeRandom[1]) resulting nil.

What do the 2 prints correspond to?

just to check if the remote event is working

fixed it, i moved the ‘end)’ below ‘print(PinCode)’ to the last line and i works!