You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
So i wanna teleport player to some position in same place.
What is the issue? Include screenshots / videos if possible!
No ideas how to do that.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tryed use Dev hub or youtube tutorials, but all tutorials about teleport between places, but i need teleport within places
My script:
local button = script.Parent
local TELEPORT_DESTINATION = Vector3.new(-184.039, 1.5, -425.691)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true
local teleportEvent = ReplicatedStorage:WaitForChild("TeleportEvent")
local function onButtonActivated()
local params = {
destination = TELEPORT_DESTINATION,
faceAngle = TELEPORT_FACE_ANGLE,
freeze = FREEZE_CHARACTER
}
end
button.Activated:Connect(onButtonActivated)
Okay so in your case all you have to do in your script is:
local button = script.Parent
local TELEPORT_DESTINATION = Vector3.new(10, 10, 10) -- Or if you want to teleport to a parts position use game.Workspace.Part (Or the path to your part).Position (ex: game.Workspace.Part.Position)
local function onButtonActivated()
local player = game.Players.LocalPlayer
local char = player.Character
local HRP = char.HumanoidRootPart
HRP.Position = TELEPORT_DESTINATION
end
script.Parent.MouseButton1Click:Connect(onButtonActivated)
So the thing is that you should teleport root with CFrame.
And the easiest way to do that is with a part
so make a anchored cantcollide invisible part and copy this code:
local plr = game.Players.LocalPlayer
local teleportpart = workspace.TeleportPart
function teleport()
if plr.Character then
if plr.Character.HumanoidRootPart then
plr.Character.HumanoidRootPart.CFrame = teleport.CFrame
end
end
end
script.Parent.MouseButton1Click:Connect(teleport)
Noticed you haven’t used the variable “teleportpart”. Is there a reason for that? Otherwise there’s no need to put time and energy to type it out.
oops, teleport needs to be teleportpart, like this:
local plr = game.Players.LocalPlayer
local teleportpart = workspace.TeleportPart
function teleport()
if plr.Character then
if plr.Character.HumanoidRootPart then
plr.Character.HumanoidRootPart.CFrame = teleportpart.CFrame
end
end
end
script.Parent.MouseButton1Click:Connect(teleport)
When the button is clicked, fire the RemoteEvent and handle the teleporting in a Script via :SetPrimaryPartCFrame()
LocalScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local teleportEvent = replicatedStorage:WaitForChild("TeleportEvent")
local cooldown = false
script.Parent.MouseButton1Click:Connect(function()
if cooldown then return end cooldown = true
teleportEvent:FireServer()
wait(1) -- Cooldown time
cooldown = false
end)
Script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
replicatedStorage.teleportEvent.OnServerEvent:Connect(function(player)
local player = players:FindFirstChild(player.Name)
if not player then return end
player.Character:SetPrimaryPartCFrame(CFrame.new(-184.039, 1.5, -425.69))
end)
My bad if there are any spelling mistakes since I typed this up here. Also, I implemented a button cooldown system so that the RemoteEvent isn’t abused.
local plr = game.Players.LocalPlayer
local teleportpart = workspace.TeleportPart
function teleport()
if plr.Character then
if plr.Character.HumanoidRootPart then
plr.Character.HumanoidRootPart.CFrame = teleportpart.CFrame
end
end
end
script.Parent.MouseButton1Click:Connect(teleport)
local button = script.Parent
local TELEPORT_DESTINATION = CFrame.new(-184.039, 1.5, -425.691)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true
local function onButtonActivated()
local c = game.Players.LocalPlayer.Character
local params = {
destination = TELEPORT_DESTINATION,
faceAngle = TELEPORT_FACE_ANGLE,
freeze = FREEZE_CHARACTER
}
c:PivotTo(params.destination * CFrame.new(0, c.Humanoid.HipHeight, 0) * CFrame.Angles(0, math.rad(params.faceAngle), 0))
if params.freeze then
c.PrimaryPart.Anchored = true
end
end
button.Activated:Connect(onButtonActivated)