Use Value in the path to part

I need to use a value from array as name of the map in the path to it

The Game says that that array[1] is not there

function Voting.PrepareGui(array)
	local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("VotingPrepareGui")
	Remote:FireAllClients(array[1], game.ServerStorage.Maps.array[1].Image)
	Remote:FireAllClients(array[1], game.ServerStorage.Maps.array[2].Image)
	Remote:FireAllClients(array[1], game.ServerStorage.Maps.array[3].Image)
end

So the array is always 3 words that are same to maps names in explorer. I need make the game read it not like “Maps.array[1].Image” but “Maps.City.Image”.

4 Likes
function Voting.PrepareGui(array)
   if typeof(array) == 'table' and array ~= nil then
      local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("VotingPrepareGui")
	  Remote:FireAllClients(array[1], game.ServerStorage.Maps.array[1].Image)
	  Remote:FireAllClients(array[1], game.ServerStorage.Maps.array[2].Image)
	  Remote:FireAllClients(array[1], game.ServerStorage.Maps.array[3].Image)
  else
      warn('Array ~= nil or not table')
   end
end

If it does not know let me know whats in the output.

3 Likes

No, The problem is another. It is always an array but it wont read part of it as what it contains.
Like, I give him box and he sees box, but I need game to open that box. I need to get the value (name of map) hiding in that part of array.

1 Like

can you show the code where you receive the event? and also where you call the function prepareGui?

on array[1], array[2], and array[3], replace it with:

array:GetChildren()[1]
array:GetChildren()[2]
array:GetChildren()[3]

1 Like
	if  GameM.GetPlayers() > 1 then
		local array = Voting.MapsGet(3)
		Voting.PrepareGui(array)
		Voting.Start()
		wait(15)
		Voting.End()
		GameM.RolesGive(PlayersAmount)
		local Map = Maps[math.random(1, #Maps)]
		GameM.LoadMap(Map)
		GameM.LoadPlayers()
		Intermission:Stop()
		Playing:Play()
		GameM.GameRound()
		GameM.Clear("DamageZone")
		GameM.BackToLobby()
		GameM.MapUnLoad()
	else
		Remote:FireAllClients("Need More Players")
		wait(3)
	end

This is part code where I call function, All is requed and it works

local Voting = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("VotingPrepareGui")
Voting.OnClientEvent:Connect(function(MapName, Image)
	script.Parent.MapText1.Text = MapName
	script.Parent.Image = Image
end)
type or paste code here

And this is one of the codes that receives, But it cant get image because path is not complete, array[1] is not in maps because it is read as “array[1]” not “City”

array is not a valid member of Folder “ServerStorage.Maps”

still same issue

Try this:

function Voting.PrepareGui(array)
    local array1 = array[1]
    local array2 = array[2]
    local array3 = array[3]
	local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("VotingPrepareGui")
	Remote:FireAllClients(array1, game.ServerStorage.Maps.array1.Image)
	Remote:FireAllClients(array2, game.ServerStorage.Maps.array2.Image)
	Remote:FireAllClients(array3, game.ServerStorage.Maps.array3.Image)
end

Also if this doesn’t work can you show me what are the values in array?

1 Like

Try using WaitForChild() to see if it corrects anything.

1 Like

The problem is not in that he cant find. Problem that it is not read as it is meant

Nah, Does not work. Now he errors array1 as it is a name of map that he cant find

The values in array are randoming so I can’t just say Names of maps I have
Example:
{“City”, “Desert”, “Grass”}

Can you copy and paste the exact error given?

array1 is not a valid member of Folder “ServerStorage.Maps”

your code. It thinks array1 is a name, but name is thing inside

Try printing what array1, array2, and array3 is.

printed:
Desert
City
Grass
But game does not understand it, is there any convertor for that?

Try using waitforchild like this: game.ServerStorage.Maps:WaitForChild(array1).Image" for each line.

If it still gives a warning it means that the objects aren’t created

2 Likes

Yes, Now it reads value as it was meant. It opens array because of WaitForChild(). Thank you!

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