Obby Scripting Help

Hello, my name is Chrissified and I need help with a script that makes players teleport where they last were when they die like if they were on a block and fell, they would teleport back on the block. You would only be able to do that 2 times and then you would go back to the stage checkpoint.

Search the developer.roblox.com site, there are lots of tutorials there.

1 Like

you can use a variable and set it to the Characters HumanoitRootPart.CFrame when the Humanoid.FloorMaterial is set(use a changed event connected to fire function) then after they die use that variable to set the HRP cframe

local MaximumDeaths = 2
game.Players.PlayerAdded:Connect(function(Player)
	local StopCoroutine = false
	local Deaths = -1
	local LastStandingCFrame = nil
	Player.CharacterAdded:Connect(function(Character)
		StopCoroutine = true
		wait(0.01)
		print("Deaths:",Deaths,"MaxDeaths:",MaximumDeaths)
		if Deaths < MaximumDeaths then
			print("Deaths < MaxDeaths")
			local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
			local Humanoid = Character:WaitForChild("Humanoid")
			print("HRP found")
			if LastStandingCFrame ~= nil then
				Deaths += 1
				print("LSC not nil")
				HumanoidRootPart.CFrame = LastStandingCFrame
			else
				print("LSC nil")
			end
			print("Before coroutine")
			coroutine.wrap(function()
				print("Inside coroutine")
				StopCoroutine = false
				local CastedTick = tick()
				repeat
					wait()
					if tick() - CastedTick >= 1 then
						CastedTick = tick()
						local raycastParams = RaycastParams.new()
						raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
						raycastParams.FilterDescendantsInstances = {Character}
						raycastParams.IgnoreWater = true
						local raycastResult = workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0,-5,0), raycastParams)
						if raycastResult and Humanoid.Health > 0 then
							if raycastResult.Instance.CanCollide and not raycastResult.Instance.Locked then
								print("Raycast Instance: "..raycastResult.Instance.Name)
								LastStandingCFrame = HumanoidRootPart.CFrame
							end
						end
					end
				until
					StopCoroutine == true
			end)()
		else
			print("Deaths > MaxDeaths")
			Player:Kick("Loser")
			--StopCoroutine = nil
			--Deaths = nil
		end
	end)
end)

RaycastTest.rbxl (26.2 KB)

Where do I put that script at?

It goes in serverscript service but you cant just plop it in, you will need to learn about it and modify it