Ok, lets try it!
First Step : First of all we need to know what is the "CFrame" function and how and where we can apply it. So I'll give you a link so you can see how to use the CFrame option.
Link : [https://developer.roblox.com/en-us/api-reference/datatype/CFrame]
Second Step : Second, we need to know where we want to teleport the player. So if we want to teleport it to a Part.Position of some Model then we can use the next pice of code...
local tpPart = workspace:FindFirstChild("TeleportingPart")
local toucTpPart = script.Parent
local function onTouch(hit)
local character = hit.Parent
if character then
character.CFrame = CFrame.new(tpPart.Position)
else
print("The character doesn't exist!")
end
end
script.Parent.Touched:Connect(onTouch)
And that's how we telepor a player to determinated position. But... How we can do this for a click button?
Well... Lets discover it!
Third Step : We need to know the differences between a LocalScript and a Script, in this case we will use a Script, so create it and parent it to the Button.
Fourth Step : Enjoy coding! You always have to enjoy what are you doing! Play some music while you script some lines. Or even you can play a game to be relaxed!
Lets get into the code!
local button = script.Parent
local tpPart = workspace:FindFirstChild("tpPart")
local function teleportFunction(click)
local player = click.Parent
if player then
local character = workspace:WaitForChild(player.Name)
if character then
character.CFrame = CFrame.new(tpPart.Position)
end
end
end
button.MouseButton1Click:Connect(teleportFunction)
local warnMessage = "The code is incorrect!"
pcall(warnMessage)
And that's how we can teleport a player!
I hope my answer already solve your question. If it did please accept my answer, that will help me a lot!
Keep scripting!
1 comment
Just letting you know, you don't need to have the quotation marks when you put down Vector3, Udim, CFrame and other number-based values.