Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to teleport when you touch a model?

Asked by 2 years ago

I am creating a house small on the inside big on the outside!!! Please help me.

3 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

From how I read it, you want to make something like were you go into a large building, and you get teleported to a smaller building in the game.

This can be done through setting a CFrame and the .Touched event. First, you want a hitbox around the door, this will be the part a player touches to enter the house. In properties, set CanColide to False and Transparency to 1.

Inside the hitbox add a script. In the script, delete the print("Hello World!")

Add a part where it will teleport you to when you exit / enter away from the hitbox, so the player wont exit / enter the building and teleport back in due to touching the hitbox. Make this transparency to 1 and cancollide to false

Rename the part to something like House1Exit / House1Enterance .

In the script, put the code as:

local Target = workspace:FindFirstChild("Target Parts Name Here") -- Replace "Target Parts Name Here" with the name off the part, such as local Target = workspace:FindFirstChild("House1Enterance")
script.Parent.Touched:Connect(function(Hit)
    if game.Players:GetPlayerFromCharacter(Hit.Parent) then
        -- The player is real, it's not something like an unanchored part falling on it.
        Hit.CFrame = Target.CFrame
    end
end)

Now, repeat this for the exit.

Code Explanation

  • local Target = workspace:FindFirstChild("Target Parts Name Here") -- Replace "Target Parts Name Here" with the name off the part, such as local Target = workspace:FindFirstChild("House1Enterance") From this, I am declaring the Target, which should be a base part as the first child found with the name you put in, this should be the part you made to teleport the player to.

  • script.Parent.Touched:Connect(function(Hit) This simply will cause the code up until end) to run when the part is touched, this can be anything from a player to an unanchored part falling onto it. It then returns Hit as a value off what touched it.

  • if game.Players:GetPlayerFromCharacter(Hit.Parent) then This will run the code up untill end if the game can get a player from the Parent off hit, if not the code won't run. This is usefull to add because it prevents things such as unanchored parts running the code due to it checking if it is actually a player touching it.

  • Hit.CFrame = Target.CFrame This will simply set the CFrame off the part that Hit the hitbox to the Targets CFrame, teleporting the Player.

Some Usefull links

0
Thanks, it works really good wasdupup 12 — 2y
0
Can you fix the tripping wasdupup 12 — 2y
0
I believe the tripping is from the height you have the part you teleport to. If it is too low, you might get a body part stuck into the ground then it looks like you tripped to get it unstuck, if its too high you fall, and it looks like you tripped. Jay123abc2 241 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Are you wanting to teleport somewhere in your game?? Here is my model Model

Or do you want to teleport to another game?? Here is my other model. Model

I would recommend to look how I coded it

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Just set the primarypart cframe to wherever you want to teleport them to Model:SetPrimaryPartCFrame()

--inside a touched script or whatever
local teleportedYet = false
task.spawn(function()
    repeat task.wait() until teleportedYet
    teleportedYet = false
    Model.Humanoid.Walkspeed = 16
end)
local targetcf = CFrame.new()--your target
Model.Humanoid.Walkspeed = 0
Model:SetPrimaryPartCFrame(cf)
teleportedYet = true

0
What do you mean and what things would I put in the model wasdupup 12 — 2y

Answer this question