Click on part to teleport player to position

  1. What do you want to achieve? Keep it simple and clear!

I have several parts that when player clicks on one it will spawn him on position

  1. What is the issue? Include screenshots / videos if possible!

The issue is that idk how to make the script :frowning:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I started looking for solutions on dev forum but nothing yet…

Thank you for the answer! :slight_smile:

Placing a script inside of a part with a ClickDetector:

local position = CFrame.new(0,0,0);

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player.Character.HumanoidRootPart.CFrame = position;
end)

Replace the CFrame in Position with the position you would like the player to be teleported to.

1 Like

Yes that would work but I didn’t mention above because i forgot but here i have like starter camera

Should still work about the same. Just place ClickDetectors inside of the arrows, and the code should still run fine.

Are you sure it’s not teleporting the player? It might still be teleporting the player, and your camera is just still in the map screen.

ll check camera script but nothing is in output

Nothing would need to be in the output, since it is working as intended. What you need to do is that you need to fire the client (from the script with the ClickDetector in it) on teleport to change the subject of the camera.

  1. Make a folder with the teleporter parts :open_file_folder:
  2. Add 1 script which references to the folder (outside of it)
  3. Type:
local Folder = -- reference to folder
local TpParts = Folder:GetChildren()

for i,part in(TpParts) do
part:FindFirstChild("ClickDetector").MouseClick:Connect (function(plr)
plr.Character.HumanoidRootPart.CFrame = part.CFrame
end)
end

Im sorry if there’s a mistake in the code, I’m typing it from my cellphone.

1 Like

Read over this again, it would teleport the player to the part with the ClickDetector

very funny what just happend :))

As I said in my response to his code.

cant i just like when the part is clicked camera is destroyed

Try it and see if it works, I don’t know if that will but it might

btw that helps by any chance

You’ll want to fire the client from a RemoteEvent in ReplicatedStorage when you click the ClickDetector.

Client-side, you’ll want to add this to your script:

game.ReplicatedStorage.CameraEvent.OnClientEvent:Connect(function()
    cam.CameraType = Enum.CameraType.Custom;
    cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid;
end)

You’ll, of course, want to add a RemoteEvent (called CameraEvent in my script) to ReplicatedStorage.

Afterwards, you’ll want to place this code inside of each part with a ClickDetector (and change the Position variable accordingly to where that button should send the player).

local position = CFrame.new(0,0,0);

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player.Character.HumanoidRootPart.CFrame = position;
    game.ReplicatedStorage.CameraEvent:FireClient(player);
end)
1 Like

which script must i add that to?

game.ReplicatedStorage.CameraEvent.OnClientEvent:Connect(function()
cam.CameraType = Enum.CameraType.Custom;
cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid;
end)

to client handler of camera?

You’ll have to add the first script to your client-side camera handler, yes.

local cam = workspace.CurrentCamera

local camPart = workspace[“CameraPart”]

local mouse = game:GetService(“Players”).LocalPlayer:GetMouse()

–// Set cam

repeat

wait()

cam.CameraType = Enum.CameraType.Scriptable

until

cam.CameraType == Enum.CameraType.Scriptable

–// Move cam

local maxTilt = 50

game:GetService(“RunService”).RenderStepped:Connect(function()

cam.CFrame = camPart.CFrame * CFrame.Angles(

math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),

math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),

0

)

end)

game.ReplicatedStorage.CameraEvent.OnClientEvent:Connect(function()

cam.CameraType = Enum.CameraType.Custom;

cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid;

end)

XD im
out of idea

I see your script, but does it work?