Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make player spawn in a Place that isn't the starter place?

Asked by
Kami_Yo 72
5 years ago

I have a teleporter part in my game that allows the player to move from place to place in the game. But I also want it set up so the game remembers what place they were in last and then use that as a the Place they spawn into instead of the starter place.

    local TeleportService = game:GetService("TeleportService")

    local Place = 2664772501
    script.Parent.Touched:Connect(function(hit)

    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if player then

    game.ReplicatedStorage:WaitForChild("FadeInEvent"):FireClient(player)

    player.Character.Humanoid.WalkSpeed = 0

    TeleportService:Teleport(Place, player)
   end
end)

This is how I teleport them. I already have a way of saving the place they teleported to and everything now I'm just wondering of how to set it up so that is where they spawn into when they leave the game and come back again.

I was thinking of simply using the same code when the player comes into the game (starter place) like this:

game.Players.PlayerAdded:Connect(function(player)
    local Place = <whatever I saved>
    TeleportService:Teleport(Place, player)

Is that a good way of setting it up or is there another better way that I'm not aware of?

1 answer

Log in to vote
0
Answered by
a4aw -5
5 years ago

Use datastore to check & save the last known place in your game they visited. Using onPlayerAdded and DataStoreService this should be well possible, alright?

0
Yes that's possible, but I wouldn't really call this an answer. SnowFunsize 55 — 5y
0
Yeah, I just got it to work this way. I pretty much just save the ID when they hit the teleporter and then do a check on startup to see if the place they are in matches the ID I saved and if not, teleport them to that place. Kami_Yo 72 — 5y
Ad

Answer this question