I’m going to give a very simplified version of this for you. The way that I’ve been told to use is PivotTo, theres a scripting example of what you’d need to put into your code below.
local Character = game.Workspace:FindFirstChild("PlayerName")--[[Change this to what the character of the person you want to change is,]]
Character:PivotTo() -- Put the CFrame of where you want the person to go here.
I was thinking of something like this, would it work too?
local Players = game:GetService("Players")
local function teleportToLocation(player)
local teleportLocation = Vector3.new(0, 100, 0)
player.Character:SetPrimaryPartCFrame(CFrame.new(teleportLocation))
end
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " has joined the game.")
player.CharacterAdded:Connect(function(character)
print(player.Name .. " has spawned.")
character.Humanoid.Died:Connect(function()
if character.Humanoid.Health == 0 then
print(player.Name .. " has respawned using the reset button.")
respawns using the reset button
teleportToLocation(player)
end
end)
end)
end)
Not exactly,
Could that work…?, possibly; but there’s a much easier way to do this that’s less confusing.
First, assuming you want the player to die, you don’t need to check if the characters health is 0, as when the Died event is fired… the players health will be 0.
Now, if you want the player to teleport to a specific location when they reset… then almost everything is good here. All you need to do is change SetPrimaryPartCFrame to PivotTo, and it should work. (NOTE: This will put the player in the exact position given, even if there’s an object blocking the area. If you don’t want this to happen, use @TomPlays63’s method and change SetPrimaryPartCFrame to MoveTo)
For teleporting… MoveTo has the possibility of walking a player to their destination, and can be affected by parts in the way. PivotTo will strictly teleport the player to the location, no matter what’s in the way.
Thank you all very much for your comments, they were very helpful! I have marked the last answer as a solution since it was the one that best suited my needs, thank you all!