Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a teleport pad that takes you back to last touched checkpoint? (Obby)

I am having trouble with this. I want it to be similar to Mega Fun Obby. When you fall down or touch a kill brick, you don't die, but you instead get teleported back to your last touched checkpoint. I think they achieved this by using an invisible part with some code that makes the player teleport to the last touched checkpoint. Any help will be appreciated.

2 comments

0

So, one thing I recommend, look into having invisible bricks underneath your obby, once that's set... look into teleporting the humanoid of whoever touches it to a certain value, that's as much as I can help with.

0

Please refrain from re-asking your question. Your original question already has an answer.

1 answer

One way of doing this would be to add an ObjectValue to the player's character and assigning that value to the checkpoint part that the player touched. Here's how the code would look like in the checkpoint part:

-- This script should be inside the checkpoint part

local checkpoint = script.Parent -- defining the checkpoint

checkpoint.Touched:Connect(function(part) -- fires when checkpoint part is touched
	local humanoid = part.Parent:FindFirstChild('Humanoid')

	if humanoid then -- checking if a player touched the checkpoint part
	local PlayerCheckpoint = humanoid.Parent:FindFirstChild('ObjectValue') -- finding the object value in the player's character
	
	if not PlayerCheckpoint then return end -- checking if player has an object value in their character to prevent error messages
	PlayerCheckpoint.Value = checkpoint -- assigning the value of ObjectValue to the checkpoint part

	end
end)

For the KillBrick that will teleport the player back to their checkpoint, insert this script.

-- This script should be inside of KillBrick

local KillBrick = script.Parent

KillBrick.Touched:Connect(function(part) -- fires when killbrick is touched
	local humanoid = part.Parent:FindFirstChild('Humanoid')

	if humanoid then -- checking if a player has touched the killbrick
		local character = part.Parent
		local PlayerCheckpoint = humanoid.Parent:FindFirstChild('ObjectValue') 
		
		if not PlayerCheckpoint then return end -- checking for the ObjectValue to prevent message errors
		character:MoveTo(PlayerCheckpoint.Position + Vector3.new(0, 5, 0)) -- teleports the player to their checkpoint
	end
end)

You'll also need a script that will insert an ObjectValue to the player's character when they join the game. For that, you'll have to use the .CharacterAdded event to create an ObjectValue for the player's character using Instance.new(). Here's the script for that.

- Insert this script into ServerScriptService

game:GetService('Players').PlayerAdded:Connect(function(player) -- fires when a player has joined the game
	player.CharacterAdded:Connect(function(character) -- fires when the player's character is loaded
		local ObjectValue = Instance.new('ObjectValue') -- create an ObjectValue
		ObjectValue.Parent = character -- Parents the ObjectValue to the character
	end)
end)

1 comment

0

Let me know if you have any issues.

This discussion is preserved as it was. New answers, comments, and votes are closed.