I am trying to make a TextButton Where when you press it it tps you back to home base.
But i dont really know how you can do that, can anyone help me with this?
I am trying to make a TextButton Where when you press it it tps you back to home base.
But i dont really know how you can do that, can anyone help me with this?
you'll use a RemoteEvent so the server can teleport the player and make the client listen for when the button is clicked.
client:
--inside the TextButton
local remote = game.ReplicatedStorage.RemoteEvent -- mayb this was the remote event
local button = script.Parent
button.Activated:Connect(function()
remote:FireServer("teleportToHome") -- fire to the server
end)
server:
--located inside ServerScriptService
local remote = game.ReplicatedStorage.RemoteEvent
local spawn = workspace.Spawn -- define where the spawn is for the homebase
remote.OnServerEvent:Connect(function(player, teleportToHome)
if teleportToHome == "teleportToHome" then
player.Character:SetPrimaryPartCFrame(spawn.CFrame.Position)
--[[
if your wondering what the "player" parameter is, its the player or client that called the remote event
--]]
end
end)
You can use Character:MoveTo(workspace.Spawn.Position) here is a example:
local player = game.Players.LocalPlayer -- Get player
local char = player.Character or player.CharacterAdded:Wait() -- Get player character or wait for player character
local Spawn = workspace:WaitForChild("Spawn") -- Put spawn location here
script.Parent.MouseButton1Click:Connect(function() -- On click in button
char:MoveTo(Spawn.Position) -- Teleport character to spawn.
end)
Hope it helped :D
Errors? tell-me on comments
Wiki pages:
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
thx for the help!
No need to use remotes. You can teleport the player from a LocalScript.
you dont need to use RemoteEvents for this, and on player.Character:SetPrimaryPartCFrame() you can use player.Character:MoveTo(spawn.Position).