Need Help Scripting a Checkpoint System

I need a checkpoint system for my game, but the problem is that it needs to save for a part that’s controlled by a player, not a checkpoint for the player itself. The part is a sphere with a BodyForce item and a script to control it, but I can’t figure out how to save the progress when you leave and rejoin.

1 Like

Can you please explain better? It needs to save the information of the sphere?

It needs to save the location of the sphere. If you need more information about the project then I can provide it.

Yes, more information would help greatly! It sounds like what you’re going to need to do is save a table with fields for Position or CFrame and any other data you want to save along with it.

To be honest, I don’t have a lot of experience with scripting. I have a lot of experience in building, but I’m at a loss for where to start with this script. In this game, a player controls the sphere. As soon as you spawn, it allows you to control the sphere, and it uses BodyForce, not a morph or a humanoid. I know this is possible with humanoids, but what I need help with is knowing if it can be done with a player-controlled part.

Yes, that’s completely possible with a BodyMover like you originally stated. What information are you looking to save for this checkpoint system?

The only thing I need to save is the location. In the game, you progress through different levels. I want it to save each time you complete a level, so you don’t have to go through every level again if you leave the game.

In that case, you might want to save both the level and location. There’s numerous ways you could go about saving this, but here’s one way.

Have an IntValue for the current level or on the server-script have a dictionary with the different players.

When you’re going to move the sphere, fire the server with the direction you’re wanting to move and handle that on the server.

local Players = {
	['CodeSleepRepeat'] = {
		Level = 1,
		Position = Vector3.new(0,0,0),
	}
}


RemoteEvent:FireServer('Forward')


local Players = {
	['CodeSleepRepeat'] = {
		Level = 1,
		Position = Vector3.new(0,0,0),
	}
}

function MoveForward(pos)
	return pos+Vector3.new(5,0,0)
end

function UpdateSphere(sphere,NewPos)
end

RemoteEvent.OnServerEvent:connect(function(plr,direction)
	if plr then
		if direction == 'Forward' then
			local pos = MoveForward(Players[plr.Name].Position)
			Players[plr.Name].Position = pos
			UpdateSphere(sphere,pos)
		end
	end
end)

As far as saving and loading the data;

local DSS = game:GetService('DataStoreService')
local DS = DSS:GetDataStore('WhateverYouWantToNameThis')
local Http = game:GetService('HttpService')

function SaveData(plr)
	local profile = Players[plr.Name]
	local SaveInfo = Http:JSONEncode({
		['1'] = profile.Level,
		['2'] = {profile.Position.X,profile.Position.Y,profile.Position.Z},
	})
	Players[plr.Name] = nil
	DS:SetAsync(plr.userId,SaveInfo)
end

function LoadData(plr)
	local Data = Http:JSONDecode(DS:GetAsync(plr.userId))
	Players[plr.Name] = {
		Level = Data['1'],
		Position = Vector3.new(Data['2'][1],Data['2'][2],Data['2'][3]),
	}
end

game.Players.PlayerAdded:connect(function(plr)
	LoadData(plr)
end)

game.Players.PlayerRemoving:connect(function(plr)
	SaveData(plr)
end)

Hopefully that helps better assist you and sorry if it’s a bit complex! :slight_smile:

1 Like

I have one more question about this, and how to use this script. Right now, when you complete a level, I want you to spawn at the end of that level. Would I need to add a leaderstat or a specific value to get this script to work? I’m somewhat inexperienced with scripting like this, so I’m not exactly sure what I need to do.

You just need spawn parts. Not the “SpawnLocation” instance, but just a regular part. From this, when they complete a level, keep going through the spawns and use Sphere.CFrame = Spawn.CFrame*CFrame.new(0,3,0) where 3 is just some sort of offset to keep the sphere from spawning in the part.

I still don’t know exactly how to do this. Would you mind using TeamCreate to help me set this up, that way you can see the scripts I have and how everything is set up? If you’d rather continue explaining through the DevForum, then that’s fine too. I really appreciate the help so far, I’m just having some trouble putting it all together.

I would team create if I had the time, sorry. No problem about the help; glad to be able to help. If you have any further questions, feel free to post them and I, or someone else, will be more than willing to help you. :slight_smile: For posts that aren’t quite on the same topic, you might want to create a new topic for it as you’ll be able to get better help that way.

Alright, thanks for your help, I really appreciate it.

Not that big of a deal, but ‘connect’ is deprecated.


I recommend using ‘:Connect’.