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
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)
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.