This is more of a brainstorm question, but here is what I am trying to accomplish. I could be going in the complete opposite direction with this so please keep in mind of what I'm trying to do. So I have a local script where I have a teleportation function set up, and a folder where I keep all of the teleport pads parts, and the game. This is how I currently have it set up if a player touches a part (Tele1) in Folder A, they then get teleported to part (Tele1) in Folder B but the player is teleported 5 studs away from the receiving end of this that way they don't reactivate the teleporter again. This method also works vice versa.
I have houses and other map locations that are set up so the idea is when the player steps on the Tele1 they will get teleported to that map as a Local Part. I know how to clone() and move the parent of an object to make this work.
So I want to make a Module Script where I want to make a massive table for all of my Maps aka Local Parts. What I am thinking about doing is adding a StringValue to Tele1, for example Tele1.StringValue.Value = "Area1"
However, this Part (Tele) StringValue will change with each Local Part that is in the game. That way I can use that StringValue's Value as an indicator as to where I want to go via Local Part which is located in the ReplicatedService. Now I know how to locate a folder and Get its Children which will be named after the StringValue's Value.
Now here comes the reason why I am asking for just a little help. I want to make a Table in a Module Script that way I don't have the same line of code 20 million times in a ton of unnecessary scripts where I could simply call the module script. So If the player touches the part and its StringValue's Value is Area1 they will get teleported to Area1(Map Location), and Tele2 for Area2, Tele3 for Area3, and so on. My question is this and this code is only an example as I haven't made the actual code yet and I am very capable of scripting this out myself just kinda need a pointer but how could I go about finding a Table Value location off a changing String Value? I thought about making a separate StringValue (a MasterString.Value if you will), and that would check the Tele1.StringValue.Value and then change its own value to that whatever it is. and use the Changed for when that MasterValue.Value is changed and then use that as a parameter for a changed event and then use a FindFirstChild named after the MasterValue.
local AreaLocationModuleScript = {} local Area = game.ReplicatedStorage.Area1 local clonedArea = Area:Clone() MasterValue.Changed:connect(function(NewValue) game.ReplicatedStorage.LocationFolder:FindFirstChild(MasterValue.Value) -- Use this to search for the Area i want to move to in the ReplicatedStorage.LocationFolder local Location = { Area1 = { clonedArea.Parent = game.Workspace --Tele1 with a StringValue.Value of 1 }, Area2 = { clonedArea.Parent = game.Workspace --Tele2 with a StringValue.Value of 2 }, Area3 = { clonedArea.Parent = game.Workspace --Tele3 with a StringValue.Value of 3 }, --After the Area is found it will be called in a different script to load this specific local part. } return AreaLocationModuleScript end
I know I have been extremely in depth with this but I am only trying to give whoever reads this the exact idea of what I am trying to accomplish. I am not sure if this is the right way to go for this but I was curious if there is an easier way is all or if this will even work.
I would think that you should put an ObjectValue called "Area" inside the teleport. The value would be of the area you teleport to.
local teleports = {} -- put the teleports here. for i,v in pairs(teleports) do v.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Area") then hit.Parent.HumanoidRootPart.CFrame = v.Area.Value.CFrame end end end
Otherwise, you could check the name of the teleport and check which area's name has the same number as the teleport.