Greetings, I am attempting to create a Chunk generator that loads a new area of the map (essentially it’s teleport based to the new areas.)
When the player touches the trigger;
I’m having issues laying it out and working out exactly how I’m going to do it.
The requirements of the Chunk loader are:
To find the exact chunk in question.
To recognise where the Player has travelled from and return them to that point if they return to that chunk. (Incase there are multiple entrance points.)
Personally, my concept was along the lines of:
Humanoid.Touched:Connect(function(Obj)
if Obj.Name == "ChunkLoader" then
-- Checks for applicable values within, such as Chunk Name etc.
else end
end
My issue is primarily returning the Player to the point of entry etc. Due to potential change of location and so forth.
TL;DR
Want to create a chunk loader that finds the new-chunk and notes where the Player left from, to allow the Player to return to that chunk in the event of multiple access points to avoid appearing at the wrong ‘entrance’.
if Debounce == false then
if Obj:FindFirstChild("ChunkLoader") then
Debounce = true
local Chunk = tostring(Obj.Name:match("#(.*)"))
local LoadChunk = MapChunks0:FindFirstChild(Chunk):Clone()
LoadChunk.Parent = MapChunks1
else return end
else return end
end)
UPDATE.
Although the system is working to an extent, I am still encountering issues of retuning the Player to the point of enter in the appropriate chunk.
The only way I can think of doing this is by having the interior chunks actually inside the town chunk as oppised to being seperate.
Thoughts on this?
I would connect doors to where they are supposed to go in a table, and you could even make the new player’s position relative to another door referenced so that you don’t have to worry about making Vector3 positions for all doors, although you might need to anyway, it depends. I would probably use code like this:
local DoorReference = {
-- [door] = otherDoor
}
local function teleportFrom(door)
local otherDoor = DoorReference[door]
if otherDoor then
character:MoveTo(otherDoor.CFrame * Vector3.new(0,0,5)) -- or (0,0,-5), i don't remember
-- maybe add a cooldown before otherDoor
-- can be used so there is not a danger of
-- teleporting back instantly
end
end
Note that with this method, you will have to make sure your door is facing toward the place where you want the player to be teleported. You could also just reference a part’s position in workspace or the position itself and teleport the player there.
Setting this up would not be too hard if you use collection service and instance values:
for _, door in ipairs(CollectionService:GetTagged("TeleportDoor")) do
DoorReference[door] = door.OtherDoor.Value -- instance value inside the door
end
CollectionService:GetInstanceAddedSignal("TeleportDoor"):Connect(function(door)
DoorReference[door] = door.OtherDoor.Value
end)
I will note that you will have to tag these with scripts too while connecting functions to them.
Then, you could just hook up teleportFrom to whatever you use to get players between doors. You could even use CollectionService:HasTag to make sure it is a door.