Im wanting to spawn player blocks in when they rejoin relative to their coordinate position.
I have this at the moment. centre is the middle point of the island, and position is a table with 3 numbers. Those 3 numbers resemble the position relative to the centre when the player left. So for example, when I print position, and if position prints
{
[1] = “0”,
[2] = “0”,
[3] = “0”
}
Then the block should be in the same position as the centre. Another example of
{
[1] = “2”,
[2] = “0”,
[3] = “4”
}
would be 2 blocks to the right of the centre, and 4 blocks in front.
So [1] is the x, [2] the y and [3] the z
local function TableToCFrame(tab)
return CFrame.new(table.unpack(tab))
end
function Coordinates.From(centre, position)
print(position)
local WorldSpace = centre.CFrame:ToWorldSpace(TableToCFrame(position))
local x = math.floor((WorldSpace.Position.X) * 3)
local y = math.floor((WorldSpace.Position.Y) * 3)
local z = math.floor((WorldSpace.Position.Z) * 3)
return x, y ,z
end
Island when I leave
When I rejoin, you can see the green square is the centre, but my island spawns miles off in the distance
For more context, if print
print(TableToCFrame(position))
I get
-3, -1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1 - Server - Coordinates:20
as one example. So it is returning the coordinated position