Obby script help!

hello everyone! :smile: Will be somebody able to help me with writing this script?

  1. What do you want to achieve? Keep it simple and clear!
  • 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.
  1. What is the issue? Include screenshots / videos if possible!
  • Looking for tutorials on youtube and much more.
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • Tried own script = result was nothing and much of errors.

some of the errors:

  • leaderstats is missing or cant find when i actually have one. and much more!

Thank you! :laughing:

4 Likes

Hello, @robuxgeng1000.

Errors are definitely a common issue. To help you get started, we can first tackle the leaderstats.

Here is a basic leaderstats script that you can find almost anywhere on the internet:

Server script, should be placed in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Value = 1 -- Starting level
	level.Parent = leaderstats
end)

That manages the player’s level, and shows it in the leaderstats. If you want level saving, there are too many tutorials out there that show how to connect leaderstats to datastores or other methods of data saving.

To access the data from the player, all we need to do is add a few more lines.

Inside of the PlayerAdded function, at the bottom add:

local playerLevel = player.leaderstats.Level.Value

Then, we can manage the spawning of the player on a part.

Name the part to the desired level number, then add it to our script:

local part = game.Workspace:FindFirstChild(playerLevel)
player.CharacterAdded:Connect(function(char)
    char.HumanoidRootPart.CFrame = part.CFrame
end)

Ensure that the part is not a model, but simply a part, otherwise part.CFrame won’t work. If your “part” is a model, then set a PrimaryPart for your model, and change the above part.CFrame to part.PrimaryPart.CFrame

With that done, now all we have to do is manage when the player dies, and where to respawn them at.

in our script, create a new function inside of the CharacterAdded function:

char.Humanoid.Died:Connect(function()
    char.HumanoidRootPart.CFrame = part.CFrame
end)

This will respawn the player on the part, based on the part’s name and the player’s level

The full script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Value = 1 -- Starting level
	level.Parent = leaderstats
	
	local playerLevel = player.leaderstats.Level.Value
	local part = game.Workspace:FindFirstChild(playerLevel)
	player.CharacterAdded:Connect(function(char)
		char.HumanoidRootPart.CFrame = part.CFrame
		char.Humanoid.Died:Connect(function()
			char.HumanoidRootPart.CFrame = part.CFrame
		end)
	end)
end)

Let me know if you have any other questions.

2 Likes

Thank you for your reply! But what if I already have the leaderstats saving and the checkpoints is in the folder, thanks for everything, but I would just appreciate the script. :smile: I would like to see your next respond!

2 Likes

also if you want i can send you the whole script and much more! :smile:

1 Like

Hi!

I am sorry, I thought you didn’t have anything. You mentioned that the leaderstats weren’t working so I thought you didn’t have one. My bad.

Okay, so you have the leaderstats made, and it saves.

The code from the previous reply will still work, we just need to delete some things and adjust others.

Assuming the leaderstats is set up the same way that the above is, we should be able to do this:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local playerLevel = player.leaderstats.Level.Value
		local part = game.Workspace.CheckpointsFolder:FindFirstChild(tostring(playerLevel))
		char.HumanoidRootPart.CFrame = part.CFrame
		char.Humanoid.Died:Connect(function()
			char.HumanoidRootPart.CFrame = part.CFrame
		end)
	end)
end)

The above script should be in a seperate script than the leaderstats script

What does this do?

PlayerAdded determines when a new player is added to the game
CharacterAdded waits for the player’s character to load
playerLevel is the level of the player, getting the value from the player’s leaderstats folder.
part is the part with the same name as the player’s level. The part is gotten from the CheckpointsFolder in the workspace.
Humanoid.Died tests for when a player dies
HumanoidRootPart.CFrame will get the player’s CFrame and set it to the part with the same name as the player’s level

Again, let me know if something doesn’t work or you have questions

I have to remove the spawning after reset beacuse i have this too. But it doesn’t work again

as you can se on the image down i have selected spawn point.

but when i join back to the game im still spawning at the spawnpoint and not the number of the part (and yea i have in stats level 3 so i have to spawn on part 3.)

but would you like to see my script?

2 Likes

sure, if you dont mind sending it that would be very helpful

1 Like

Okay, here it is. This one script has everything.

-- [ VARIABLES ] --

local Players = game:GetService("player")

local CheckpointsFolder = game.Workspace.Map.Obby:FindFirstChild("Checkpoints")

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) 
		
		player:WaitForChild("leaderstats")

	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

			Character:PivotTo(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)

2 Likes

1: Not sure why you’ve now made 5 topics about this, but whatever you want I guess.

2: I have updated your script, and everything should work as intended.

Some things that need to be adjusted:

  • Checkpoints need to all be a Part otherwise the spawn location will not work, change that to a part and it will automatically spawn the player into “0” if that is what stage they are on.

Other than that, just paste this script over the old one and it should work flawlessly.

-- [ VARIABLES ] --

local Players = game:GetService("player")

local CheckpointsFolder = game.Workspace:WaitForChild("Checkpoints")

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) 

		player:WaitForChild("leaderstats")
	end)

	-- [ CHECKPOINTS SCRIPT ] --

	local CheckpointsFolder = game.Workspace:WaitForChild("Checkpoints")
	
	local part = CheckpointsFolder:FindFirstChild(tostring(Stage.Value))
	player.Character.HumanoidRootPart.CFrame = part.CFrame + Vector3.new(0,2,0)
	player.Character.Humanoid.Died:Connect(function()
		player.Character.HumanoidRootPart.CFrame = part.CFrame + Vector3.new(0,2,0)
	end)
	
	player.CharacterAdded:Connect(function(Character)
		repeat
			wait()
		until Character ~= nil

		local part = CheckpointsFolder:FindFirstChild(tostring(Stage.Value))
		Character.HumanoidRootPart.CFrame = part.CFrame
		Character.Humanoid.Died:Connect(function()
			Character.HumanoidRootPart.CFrame = part.CFrame
		end)
	end)

	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(85, 255, 0)
				Checkpoint.Material = Enum.Material.Neon

				if PlayerHit.leaderstats:FindFirstChild("Stage").Value == Checkpoint.Name - 1 then
					PlayerHit.leaderstats:FindFirstChild("Stage").Value = Checkpoint.Name
					Event.CheckPointEvent:FireClient(player)
				end
			end
		end)
	end
	
			-- [ KILL BRICKS ] --

	local KillBricksFolder = game.Workspace:WaitForChild("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)

(You may need to adjust the locations of things. I changed them to replicate the issue and they have not been changed back.)

Anyway, best of luck!

Let me know if there are more questions.

Im sorry about the spamming. I just need help and thank you. I will try this and i will contact you.

1 Like

You just described a basic checkpoint script. so this should help

Read the instructions in the model. You can change the block to whatever you want, can even use a meshpart.

1 Like

This is also much simpler than remoteevents, folders, millions of scripts. Just put the script into serverscriptservice and change the number at the end of the blocks name. (Checkpoint 1, Checkpoint 2, etc…)

2 Likes

Okay, I have one question. Can i remake the leaderstats into data saving leaderstats?.

1 Like

Yeah, pretty sure you can do that. I’m not the best with scripting though and all I have ever been able to do is make it change the colour of the block. But still I’m 99% sure that’s possible

2 Likes

Working now. Thank you so much bro!

1 Like

Working too. Thank you so much bro!

3 Likes

The Checkpoint model that @pulse_tech shared does not come with leaderstat saving, however you could re-program the script to connect to your leaderstats script instead of using the built in leaderstats.

Yes. That’s right. But thank you so much bro! i did it for like 2 weeks with no results and you helped me a lot!

1 Like

Were you able to connect it to your leaderstats okay?

Yea, Yea But i think i will now use your script that you sended me

  • little credits

image

2 Likes