Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get it so I teleport back to my original location after reloading the character?

Alright so, this script is a local script inside a GUI Button. I need it so this reloads the character then, teleports that person to the same location they were in when they hit the button. I don't know how to get the location of a character. Please answer this, not comment... even if it's just a comment. If the comment helps, i'd like to be able to give you the answer reward instead of leaving the question unanswered.... What this is suppose to do in simplistic form will be below.

--Made By MillerrIAm
--------------------------------
function buttondown(player,person,value)
	game.Players[""..person]:LoadCharacter()
	wait(1)
	game.Players[""..person].Character:MoveTo(game.Players.LocalPlayer.Location)
end


script.Parent.MouseButton1Down:connect(buttondown)

Player Clicks the button, it resets them then teleports them to the spot they were just at when they hit the teleportation button. I get 662 is not a valid member of Players. No idea what i'm doing wrong. Thank you in advance for any help given!

1 answer

✓ Accepted answer

First, create RemoteEvent called Reload and put it inside ReplicatedStorage.

Script inside ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Reload = ReplicatedStorage:WaitForChild("Reload")

Reload.OnServerEvent:Connect(function(Player)
	local CFram = Player.Character.HumanoidRootPart.CFrame
    Player:LoadCharacter()
    repeat wait() until Player.Character
    Player.Character.HumanoidRootPart.CFrame = CFram
end)

Localscript inside Button

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Reload = ReplicatedStorage:WaitForChild("Reload")
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	Reload:FireServer()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.