Sending Table To Module Script Then Sending It To Script

What Am I Trying To Achieve?
I stored and made a table of player’s positions in a server script and I will need the table in another script.But to do that I am required to use module script to store the table.

Problem:
In order for my other script that needs to receive the table I would need a module script that would receive the table from the first script.I searched online and tried to see if it would help me but I couldnt understand them.

First Script thats supposed to pass the table to the module script:
local playerLocations = {}
for _,player in pairs(game.Players:GetPlayers()) do
if (player.Character.PrimaryPart.Position - player.Character.HumanoidRootPart.CFrame.Position).Magnitude < 100 then
playerLocations[player] = player.Character:GetPrimaryPartCFrame()
end
end

	local PosModule = require(script.PositionOriginModule)
	print(PosModule)

–I do not know how to send the table to the module nor how to make the second script take the table from the module

My first script:

local playerLocations = {}
for _,player in pairs(game.Players:GetPlayers()) do
if (player.Character.PrimaryPart.Position - player.Character.HumanoidRootPart.CFrame.Position).Magnitude < 100 then
playerLocations[player] = player.Character:GetPrimaryPartCFrame()
end
end

	local module = require(script.PositionOriginModule)
	module:LoadContents(playerLocations)

Module Script:
local module = {}

function module:LoadContents(contents)

print(contents)

end

return module

Second Script the takes the table from the module:
local module = require(script.PositionOriginModule)
local playerLocations = module.contents
for _,player in pairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.Position = Vector3.new(playerLocations[player])
print(player.Name)

I used some reference from another post.
Doe my one does not work,I still currently finding out why

You can use bindable fuctions instead

1 Like

you can refer this for bindable functions or you can just wait for a few movements while I code and reply…

1 Like
Script 1
local playerLocations = {}
for _,player in pairs(game.Players:GetPlayers()) do
if (player.Character.PrimaryPart.Position - player.Character.HumanoidRootPart.CFrame.Position).Magnitude < 100 then
playerLocations[player] = player.Character:GetPrimaryPartCFrame()
end
end
BindableFunction:Invoke(playerLocations)
Script 2
local playerLocations = {}
BindableFunction.OnInvoke:Connect(function(t1)
playerLocations = t1
end)
for _,player in pairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.Position = Vector3.new(playerLocations[player])
print(player.Name)
1 Like

So binables are like remote events sending information from server script to server script right?

Yea you got that right. :slight_smile:

1 Like