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