so this is my skip stage script for my one game im making
local STAT_NAME = "Stage"
local PREVENT_SKIPPING = true
(4)local checkpoints = {}
(5)
(6)local i = 1
(7)while true do
(8) local checkpoint = Workspace:FindFirstChild("Checkpoint " .. i, true)
(9) if not checkpoint then print("Last Checkpoint : " .. i-1) break end
(10) table.insert(checkpoints, checkpoint)
(11) i = i + 1
(12)end
(13)
(14)game.Players.PlayerAdded:connect(function(player)
(15) local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Model", player)
(16) leaderstats.Name = "leaderstats"
(17)
(18) local checkpointStat = Instance.new("IntValue", leaderstats)
(19) checkpointStat.Name = STAT_NAME
(20) checkpointStat.Value = 1
(21)
(22) player.CharacterAdded:connect(function(character)
(23) local goto = checkpoints[checkpointStat.Value]
(24) if goto then
(25) repeat wait() until character.Parent
(26) character:MoveTo(goto.Position)
(27) else
(28) warn("Checkpoint " .. checkpointStat.Value .. " not found")
(29) end
(30) end)
(31)end)
(32)
(33) for index, checkpoint in ipairs(checkpoints) do
(34) checkpoint.Touched:connect(function(hit)
(35) local player = game.Players:GetPlayerFromCharacter(hit.Parent)
(36) if not player then return end
(37) local humanoid = hit.Parent:FindFirstChild("Humanoid")
(38) if not humanoid or humanoid.Health <= 0 then return end
(39) local leaderstats = player:FindFirstChild("leaderstats")
(40) if not leaderstats then return end
(41) local checkpointStat = leaderstats:FindFirstChild(STAT_NAME)
(42) if not leaderstats then return end
(43)
(44) if (PREVENT_SKIPPING and checkpointStat.Value + 1 == index) or (not PREVENT_SKIPPING and checkpointStat.Value < index) then
(45) checkpointStat.Value = index
(46) end
(47) end)
(48) end
but im very unclear how I can make a datastore save script for this when a player leaves/enters my game
sorry about the script looking sloppy I added (each lines number so hopefully that helps im not sure how to make it look like how it actually does with each line and clean looking. also within my game I don't have a teams folder as the model I am currently using is (https://www.roblox.com/library/4558096741/SkipStage-GUI-Checkpoint-By-BoxyPlays) and this model doesn't have a color assignable section for the teams folder
