The character would spawn on a part that has a number in its name and according to the number in the stats the character would spawn on the part , so if the player had the number 1 in the stats it would spawn on part 1.
Hello,I’m experienced with obbies.It seems you are trying to make a checkpoint script.
You can make a server sided script,connect to player added and its character added,and then pivot its character model to a bit higher then the parts cframe
local checkpoints = workspace.Checkpoints -- example
game.Players.PlayerAdded:Connect(function(plr)
local StageValue : IntValue = plr.leaderstats.Stage -- change this one with your value name
plr.CharacterAdded:Connect(function(CharModel)
targetcframe = checkpoints[tostring(StageValue.Value)].CFrame * CFrame.new(0,3,0)
CharModel:PivotTo(targetcframe)
end)
end)
loop throught the checkpoints and check the name matching ur stage value
for i, v in pairs(checkpoints:GetChildren()) do
if tonumber(v.Name) == player.leaderstats.Stage.Value then
player.Character.HumanoidRootPart.CFrame = v.CFrame + Vector3.new(0,3,0)
end
end
I didn’t get why are you looping to access an object instead of using instancename[“childinstancename”] or instancename:FindFirstChild(“childinstancename”)
that’s looping too. we’re the same, you used tostring i used tonumber yet wer’re still the same, we are looping through the table, with diffirent ways. but we are looping. (gosh that was bad)
then It might be erroring because the scripts connects before folder instance is added,I think you should change plr.leaderstats to plr:WaitForChild(“leaderstats”)
-- [ VARIABLES ] --
local Rs = game.ReplicatedStorage
local Event = Rs:WaitForChild("Events")
local startamount = 0 -- Start amount --
local Players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("StageOneSave") -- What is game saving --
local ds2 = DataStore:GetDataStore("MoneyOneSave") -- What is game saving --
-- [ LEADERSTATS ] --
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats" -- Folder name --
leaderstats.Parent = player
local Stage = Instance.new("IntValue", leaderstats)
Stage.Name = "Stage" -- Value name --
Stage.Value = ds1:GetAsync(player.UserId) or startamount
ds1:SetAsync(player.UserId, Stage.Value)
Stage.Changed:connect(function()
ds1:SetAsync(player.UserId, Stage.Value)
end)
local Money = Instance.new("IntValue", leaderstats)
Money.Name = "Money" -- Value name --
Money.Value = ds2:GetAsync(player.UserId) or startamount
ds2:SetAsync(player.UserId, Money.Value)
Money.Changed:connect(function()
ds2:SetAsync(player.UserId, Money.Value)
end)
game.Players.PlayerRemoving:connect(function(player)
ds1:SetAsync(player.UserId, player.leaderstats:WaitForChild("Stage").Value)
ds2:SetAsync(player.UserId, player.leaderstats:WaitForChild("Money").Value)
end)
-- [ CHECKPOINTS SCRIPT ] --
local CheckpointsFolder = game.Workspace.Map.Obby:FindFirstChild("Checkpoints")
for i, Checkpoint in pairs(CheckpointsFolder:GetChildren()) do
Checkpoint.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local PlayerHit = game.Players:GetPlayerFromCharacter(Hit.Parent)
Checkpoint.Color = Color3.fromRGB(255, 0, 0)
Checkpoint.Material = Enum.Material.Neon
if PlayerHit.leaderstats:FindFirstChild("Stage").Value == Checkpoint.Name - 1 then
PlayerHit.leaderstats:FindFirstChild("Stage").Value = Checkpoint.Name
workspace.SoundFx.Success:Play()
Event.CheckPointEvent:FireClient(player)
end
end
end)
player.CharacterAdded:Connect(function(Character)
repeat
wait()
until Character ~= nil
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
HumanoidRootPart.CFrame = CheckpointsFolder:FindFirstChild(Stage.Value).CFrame + Vector3.new(0, 2, 0)
-- [ KILL BRICKS ] --
local KillBricksFolder = game.Workspace.Map.Obby:FindFirstChild("KillBricks")
for _, KillBrick in pairs(KillBricksFolder:GetChildren()) do
KillBrick.Touched:Connect(function(touchPart)
local Humanoid = touchPart.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Health = 0
end
end)
end
end)
end
end)
--
local checkpoints = workspace.Map.Obby.Checkpoints -- example
game.Players.PlayerAdded:Connect(function(plr)
local StageValue : IntValue = plr.leaderstats.Stage -- change this one with your value name
plr.CharacterAdded:Connect(function(CharModel)
local targetcframe = checkpoints[tostring(StageValue.Value)].CFrame * CFrame.new(0,3,0)
CharModel:PivotTo(targetcframe)
for i, v in pairs(checkpoints:GetChildren()) do
if tonumber(v.Name) == plr.leaderstats.Stage.Value then
plr.Character.HumanoidRootPart.CFrame = v.CFrame + Vector3.new(0,3,0)
end
end
end)
end)