✓ Accepted answer
I had this problem multiple times, and I know multiple ways to solve it. The first way is to Model:MoveTo() which teleports a person to a specific destination. The downside of using this method is that it does not keep the orientation of the player. Example:
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.B then
local me = game.Players.LocalPlayer.Character
me:MoveTo(Vector3.new(0,0,0))
end
end)
The other option and the best one in my opinion is Model:SetPrimaryPartCFrame. It keeps the orientation and position.
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.B then
local me = game.Players.LocalPlayer.Character
me:SetPrimaryPartCFrame(CFrame.new(0,0,0))
end
end)
Also, another thing you should do is wait for your character to load before your event can begin. So just put this at the top of the event:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
1 comment
Thanks Comrade!