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.
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.
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