Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

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! GrumpyTheDaddy 17 — 5y
0
oh, ok, just make that part the PrimaryPart DeceptiveCaster 3761 — 5y
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? GrumpyTheDaddy 17 — 5y
0
not really, the part should be a child of the Model not a descendant DeceptiveCaster 3761 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Found a way to reconfigure my intent completely which made it easier to explain... and do. Thanks to MCAndRobloxUnited and the tip about the PrimaryPart though, that was integral.

My solution can be found here for anyone else looking for something similar: https://scriptinghelpers.org/questions/76329/no-errors-so-why-isnt-this-spawn-on-load-script-not-working

Answer this question