Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to locate the position of a model in nested folders using a player value-name comparison?

Hi, I am trying to cobble together a script which will exist in the workspace that will help relocate players to a previous checkpoint from a value stored in the DataStore which is then mapped to a value on the character when they load in.

Please note, I'm still only at the 'google and copy/paste' stage of coding but the patience and kindness of this community is making that process a lot less reliant on other existing solutions.

So far I think I have something that would read the value stored on the character and once I can use that value to locate the model I want to MoveTo I think it would do the teleportation for me... please feel free to rip me a new one and provide any teaching moments you can.

The code starts with an overview of the folder structure in place to help you understand what I am trying to access.

--Workspace
----checkPoints
------1-25. lava
--------1
--------2
--------etc
------26-50. cloud
--------26
--------27
--------etc

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
		local progress = char.leaderstats.Stage.Value
		local checkpoint = ???HELP HERE???
        char:MoveTo(checkpoint.Position + Vector3.new(0,3,0))
        if char:findFirstChild("ForceField") then
            char.ForceField:Destroy()
        end
    end)
end)

Thanks for any help.

2 answers

✓ Accepted answer

If checkpoint is a Model (I can't tell because you didn't tell us what checkpoint is), you can only get the Position of its PrimaryPart:

local checkpoint = -- Location of checkpoint model
if checkpoint.PrimaryPart == nil then -- Always check for this before doing anything with the PrimaryPart
	checkpoint.PrimaryPart = -- Part selected as PrimaryPart
end
char:MoveTo(checkpoint.PrimaryPart.Position + Vector3.new(0,3,0))

I can't help you any further because you didn't give enough information.

4 comments

0

Sorry, I thought I had made it clear but in my attempt to do so likely made it more convoluted! Yes, checkpoint refers to a model named 1, 2, 3 etc... within that model is a part with a matching name so it is that I'm trying to locate, my issue is matching the players Stage Value to the list of checkpoints rather than a specific one... if that makes sense, sorry if not!

0

oh, ok, just make that part the PrimaryPart

0

Thanks, and please pardon my ignorance, with that in mind how would I go about setting the correct checkpoints primary part as the 'checkpoint' variable, I presume I need to index the core folders dependents or something?

0

not really, the part should be a child of the Model not a descendant

This discussion is preserved as it was. New answers, comments, and votes are closed.