How can I get the name from a TextLabel if the text was randomized in the script

Hello,

So as you can see in the titel I want to get the text from a TextLabel that was randomized before in a script. And I need that name for my second script which is connected with RemoteFunctions. But I don’t know the name cause its randomly so yea.

If someone could tell me how I can get the text from a TextLabel which was randomized so I can use it in a other script that would be very, VERY helpfull!

Can you share the scripts. To check it.

The one that randomizes the text? Or the one whith the RemoteFunctions?

wouldn’t TextLabel.Text work?
I mean just get the text after you changed it

Both please. To check them. Please

You can assign the textlabel in your script as a variable and when the remote function fires you fire server with the textlabel.


local Players = game:GetService("Players")

local function onPlayerAdded(player)
	print(player.Name)
	local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam", "ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly"}
	wait(5)

	local ReplicatedStorage = game.ReplicatedStorage.RemoteFunctions.AbortFunctions.Order1.Order1Function


	local tvOrdersRMD = {"OldTv", "Salora 58UA330"}

	local orders = player.PlayerGui.ComputerMenu.Orders.Background1.Orders
	local OrderParent = player.PlayerGui.ComputerMenu.Orders.Background1

	-- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
	local randomtask2 = math.random(#names)

	local index
	local index2
	wait(10)

	for i = 1, 6 do
		index = math.random(#names)
		index2 = math.random(#tvOrdersRMD)

		local Order = OrderParent["Order"..i]

		Order.Visible = true
		Order.Text = "Name: ".. names[index]
		Order.TVSelecter.Text = "Order: "..tvOrdersRMD[index2]
		orders.Value += 1
		local OrderValue = Instance.new("BoolValue")
		OrderValue.Name = tvOrdersRMD[index2]
		OrderValue.Parent = ReplicatedStorage
		wait(70)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Order = Instance.new("RemoteFunction")
Order.Parent = ReplicatedStorage
Order.Name = "CreateOrderRequest"



local function orderRequest(player)
		
end

Order.OnServerInvoke = orderRequest()


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local OrderFunction = ReplicatedStorage:WaitForChild("CreateOrderRequest")

script.Parent.MouseButton1Click:Connect(function()
	local Order = OrderFunction:InvokeServer()
	
end)

I wish it was that easy, but no. Cause its created with Instance.new().

Try something like this:

local Order = Instance.new("RemoteFunction")
Order.Parent = ReplicatedStorage
Order.Name = "CreateOrderRequest"

local function orderRequest(player, text)
print(text)
end

Order.OnServerInvoke = orderRequest

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local OrderFunction = ReplicatedStorage:WaitForChild("CreateOrderRequest")

script.Parent.MouseButton1Click:Connect(function()
    -----------I dont know where is the label so you can change the "script.Parent.Name"
	local Order = OrderFunction:InvokeServer(script.Parent.Name)
end)

This is unnecessary cause it doesn’t do anything or i am totally wrong that could be true tho… :roll_eyes: :roll_eyes:

And I forgot to change the title cause its a boolvalue created with Instance.new(). And with that value it will be having the same name as the randomized order as you can see in the script.

And I can’t figure out how I can make it that the second script knows what the name of the value is.

But if you know an other way to do this that also would be great!!

Instance.new() returns the instance that you made. Here is an example:

local newInstance = Instance.new("Part")

newInstance.BrickColor = BrickColor.new("Really Red")
newInstance.Name = "EEEEEE"
newInstance.Parent = game:GetService("Workspace")

To make it cross-script (allow other scripts to know what it is), depending on how your game works, the other script can listen for it added via ChildAdded/DescendantAdded, or you can send the script the value via a BindableEvent.

1 Like

I have coded a concept that might help you/give you idea :slight_smile:

--Services
local Players = game:GetService("Players")

--Variables
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui

local screenGui = PlayerGui:WaitForChild("ScreenGui")
local Frame = screenGui.Frame

--Table
local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam", "ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly"}


--Code
local folder = Instance.new("Folder")
folder.Parent = Frame


local index = math.random(#names)

local txtBoxWithRunName = Instance.new("TextBox")
txtBoxWithRunName.Name = names[index]
txtBoxWithRunName.Parent = folder


local getTextWithRunName = folder:GetChildren()
for i, child in ipairs(getTextWithRunName) do
	print(child.Name)--The Child is the random name textbox
end


--[[
Instance a new folder before instancing the text label which you would know the name of it then inside that folder instance the text label with the random name. 
Then to access it access the file and GetChildren()

Hope this suggestion helps
]]

I will test that out for sure! And I am pretty sure that that is a solution but ima try it out first.

I had that same idea before and I tried it out. But the problem is that if he/she accepted more orders then there will be more values and it will return all of them. And I don’t want that to happen yet… But if the time is there and the players want that I will use that for sure.

1 Like

One last question:

How can I send the BoolValue with the random name to the otherscript? Cause so far I only have this…;


local Players = game:GetService("Players")

local function onPlayerAdded(player)
	print(player.Name)
	local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam", "ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly"}
	wait(5)

	local ReplicatedStorage = game.ReplicatedStorage.RemoteFunctions.AbortFunctions.Order1.Order1Function


	local tvOrdersRMD = {"OldTv", "Salora 58UA330"}

	local orders = player.PlayerGui.ComputerMenu.Orders.Background1.Orders
	local OrderParent = player.PlayerGui.ComputerMenu.Orders.Background1

	-- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
	local randomtask2 = math.random(#names)

	local index
	local index2
	wait(10)

	for i = 1, 6 do
		index = math.random(#names)
		index2 = math.random(#tvOrdersRMD)

		local Order = OrderParent["Order"..i]

		Order.Visible = true
		Order.Text = "Name: ".. names[index]
		Order.TVSelecter.Text = "Order: "..tvOrdersRMD[index2]
		orders.Value += 1
		
		
		
		local OrderValue = Instance.new("BoolValue")
		OrderValue.Name = tvOrdersRMD[index2]
		OrderValue.Parent = ReplicatedStorage
		wait(70)
		
		if OrderValue then
			local BindableEvent = game.Workspace:WaitForChild("AcceptOrder")
			BindableEvent:Fire()
		end
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Order = Instance.new("RemoteFunction")
Order.Parent = ReplicatedStorage
Order.Name = "CreateOrderRequest"

local BindableEvent = game.Workspace:WaitForChild("AcceptOrder")


local function orderRequest(player, text)
	BindableEvent.Event:Coccent(function()
		
	end)
end

Order.OnServerInvoke = orderRequest

Can you guys help me with that? @iamtryingtofindname, @CrazySnoopylove

Look into Remote Events and send that value with a remote event or another solution would be to set a value/attributes and detect .Changed()

I’ve been doing some scripting but, the only thing is that it doesn’t says the randomized name of the BoolValue even tho I send it to the other script.(Not sure about that… the script may be incorrect)

And if I put a print statement it doesn’t prints it. Here’s the script;


local Players = game:GetService("Players")

local function onPlayerAdded(player)
	print(player.Name)
	local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam", "ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly"}
	wait(5)

	local ReplicatedStorage = game.ReplicatedStorage.RemoteFunctions.AbortFunctions.Order1.Order1Function


	local tvOrdersRMD = {"OldTv", "Salora 58UA330"}

	local orders = player.PlayerGui.ComputerMenu.Orders.Background1.Orders
	local OrderParent = player.PlayerGui.ComputerMenu.Orders.Background1

	-- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
	local randomtask2 = math.random(#names)

	local index
	local index2
	wait(10)

	for i = 1, 6 do
		index = math.random(#names)
		index2 = math.random(#tvOrdersRMD)

		local Order = OrderParent["Order"..i]

		Order.Visible = true
		Order.Text = "Name: ".. names[index]
		Order.TVSelecter.Text = "Order: "..tvOrdersRMD[index2]
		orders.Value += 1
		
		
		print(Order)
		local OrderValue = Instance.new("BoolValue")
		OrderValue.Name = tvOrdersRMD[index2]
		OrderValue.Parent = ReplicatedStorage
		print(OrderValue.Name)
		
		local bf = game.Workspace:WaitForChild("AcceptOrder")
		print(bf)
		bf:Invoke(OrderValue)
		print(OrderValue)
		wait(70)
		
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

And

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Order = Instance.new("RemoteFunction")
Order.Parent = ReplicatedStorage
Order.Name = "CreateOrderRequest"
print("OK1")

local bf = game.Workspace:WaitForChild("AcceptOrder")


local function orderRequest(player, text)
	print(player)
	
end

Order.OnServerInvoke = orderRequest

local function AcceptOrder(player)
	print("ok")
	print(bf)
end

bf.OnInvoke = AcceptOrder

@CrazySnoopylove, @iamtryingtofindname

When you are randomizing the names, I assume you are using some sort of key for encrypting it, if you’re not, I suggest you do so and then you can use the same key to decrypt names when you need to.

Can you show me an example please? Or a link, if that goes faster.(so you don’t have to type…)