Obby script help

Hello devs, I would like help with a script.

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.

  • What solutions have you tried so far?

Looking for some tutorials on youtube and more…

Thank you.

2 Likes

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)

Thank you so much, i will try it now.

I tried this script and the script doesn’t work, I tried to fix it somehow but it still doesn’t work. Do you have any other ideas for the script?

Did it gave an error to output?

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

hey can i ask you what obby did you make? i’m really intrested

image

but i actually have it with name “leaderstats”

I didn’t get why are you looping to access an object instead of using instancename[“childinstancename”] or instancename:FindFirstChild(“childinstancename”)

Yeah I told you it was an example

Didn’t you made leaderstats code? Its main bone of an obby checkpoint system
Actually i didn’t told u to make one sorry

actually i have the whole leaderstats script:

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)

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)

we are loop brothers

1 Like

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”)

2 Likes

or just put the entire code inside the leaderstats code to make stuff cleaner and easier to deal with

1 Like

Yeah a nice option to prevent making too much connections but i think this way would be more clear to read the code

1 Like

I have everything in one script actually:

-- [ 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)
1 Like

why the f"ck did you put both of our codes in your script??

I think you aren’t really into scripting,instead of changing root part cframe just pivot the character

I just started some months ago