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

How can I teleport players within a game by touching something with a key?

I have made a keycard-like entrance that requires the player to hold and item and touch a secret object, but instead of opening some kind of door it teleports them to a place within the same game, so it's not putting them in a different game. Here is my code:

script.Parent.Bottle.Touched:Connect(function(hit)
	print("touched")
	if hit.Parent.Name == "Key" then
		print("teleport")
		game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(96, 2.5, 48.5))
	end
end)

PS, the prints are for me debugging my code. The error I get is that Player is not a member of Workspace.

1 answer

✓ Accepted answer

Create a part in workspace named "Teleport" (Case sensitive) and use this. The key must be out and the player has to touch the object with the key out. BTW when tools are out they are parented to the character.

script.Parent.Bottle.Touched:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Key") and hit.Parent:FindFirstChild("Key"):IsA("Tool") then
        print("teleported")
        hit.Parent.HumanoidRootPart.CFrame = game.Workspace.Teleport.CFrame * CFrame.new(0, 5, 0)
    end
end)

1 comment

0

Thanks! Also thanks for the extra info with the tools being parented to the character, that will definitely help in the future.

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