I Can't detect a table value on another script

Hello! i have a script that makes a table, I need to take a value from this table and use it in another script.

TABLE SCRIPT

local debounce = false
StoryDoor.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)	
		debounce = true
		if #PlayerProperty == 0 or #PlayerProperty < 2 and not #PlayerProperty then
			hit.Parent.HumanoidRootPart.Position = TeleportIn.Position
			table.insert(PlayerProperty, plr)
			task.wait(.1)
			print(PlayerProperty)
			LeaveGUIEvent:FireClient(PlayerProperty[1])

LOCAL SCRIPT

local LeaveGUIEvent = game.ReplicatedStorage.Lobby.LeaveGUI

local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420

LeaveGUIEvent.OnClientEvent:Connect(function(player1)
	local Players = game:GetService("Players")
	print(player1)
	local playerId1 = Players:GetPlayerByUserId(player1)
	script.Parent.Enabled = true
	script.Parent.Player1PhotoButton.Image = playerId1:GetUserThumbnailAsync(playerId1, thumbType, thumbSize)
end)

when i tried to take a output print from main script, it works well and gives table value correctly however at the local script it gives nil

Is PlayerProperty[1] the player you want to fire the event to or?

1 Like

Is the table a variable in that script or do you update somewhere else?

1 Like

yes also the player i want to get profile photo in local script

yes it’s just a variable in this script

Because your checking if there is no value in the table then couldn’t you just do PlayerProperty[1] = plr

1 Like

Isn’t that just the local player or do you want to use a different one?

1 Like

i will get another player value later too

Ok then you can do

local player1 = game.Players.LocalPlayer
local playerId1 = Players:GetPlayerByUserId(player1)
script.Parent.Enabled = true
script.Parent.Player1PhotoButton.Image = playerId1:GetUserThumbnailAsync(playerId1, thumbType, thumbSize)
1 Like

i can try it lemme a sec please

yes i can work it like that but i will have to add another user’s value to the script later on

second player gonna take
Player2PhotoButton.Image that’s why im not using the local player directly

sadly not working, still gives “nil” on local script

Can you show the table output from the serverscript?

1 Like

its my bad but i dont know how to do this as i dont work on tables very often

You have not actually sent your table over, to achieve this you need to do:

LeaveGUIEvent:FireClient(PlayerProperty[1], PlayerProperty[1])

This is because the first argument is the target player, and the second argument is then the player themselves (any arguments proceeding are sent along). You cannot send objects however so this is unlikely to work at all.

Based on your methodology alone however here is a solution:
As its a client script you can instead assume this is the client.

-- Assuming you know the client
local LeaveGUIEvent = game.ReplicatedStorage.Lobby.LeaveGUI

local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420

LeaveGUIEvent.OnClientEvent:Connect(function()
	local Players = game:GetService("Players")
	local player1 = Players.LocalPlayer
	print(player1)
	local playerId1 = Players:GetPlayerByUserId(player1)
	script.Parent.Enabled = true
	script.Parent.Player1PhotoButton.Image = playerId1:GetUserThumbnailAsync(playerId1, thumbType, thumbSize)
end)

Assuming you do not want this behaviour and would rather instead do it based on the ID sent:

-- Assuming you know sent the client
local LeaveGUIEvent = game.ReplicatedStorage.Lobby.LeaveGUI

local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420

LeaveGUIEvent.OnClientEvent:Connect(function(PlayerID)
	local Players = game:GetService("Players")
	print(PlayerID)
	local playerId1 = Players:GetPlayerByUserId(PlayerID)
	script.Parent.Enabled = true
	script.Parent.Player1PhotoButton.Image = playerId1:GetUserThumbnailAsync(playerId1, thumbType, thumbSize)
end)

The amended server code would then be:

local debounce = false
StoryDoor.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)	
		debounce = true
		if #PlayerProperty == 0 or #PlayerProperty < 2 and not #PlayerProperty then
			hit.Parent.HumanoidRootPart.Position = TeleportIn.Position
			table.insert(PlayerProperty, plr)
			task.wait(.1)
			print(PlayerProperty)
			LeaveGUIEvent:FireClient(PlayerProperty[1], plr.UserId)
1 Like

Oh ye forgot about that they could try using FireAllClients(PlayerProperty[1])

1 Like

In either situation, you need to make sure you handle the code accordingly. You should treat FireAllClients and FireClient as two completely different functions with different ways of forming arguments, because they are just that.

My solution above completely outlines a solution that will work at the end in both scenarios.

As mentioned:
A player table is actually an object in Roblox and cannot cross the server-client boundary.

1 Like

Oh yeah! i get you, thank you for your detailed and long post, now i understand how it works and i get it. really cheers.

Ok you can send the second player thru the remote.

LeaveGUIEvent:FireClient(PlayerProperty[1], SecondPlayer)
1 Like

Yeah, im gonna work on this now