i wanna make it so when the player joins from a place they get a specific spawn location, the only problem i have is making the spawn location different, otherwise the script works.
local players = game:GetService("Players")
local place1Id = 128194721848749
local place2Id = 136403810915632
local place3Id = 133711048400377
local joinData = game:GetService("TeleportService"):GetLocalPlayerTeleportData()
if not joinData then return end
if joinData.comingFromPlace == place1Id then
print("spawn 1")
players.LocalPlayer.RespawnLocation = game.Workspace.SpawnLocation
end
if joinData.comingFromPlace == place3Id then
print("spawn 2")
players.LocalPlayer.RespawnLocation = game.Workspace.SpawnLocation2
end
The first condition was met, so you may just need to check what its TeamColor property is set to if it’s also meant to be specific to a team, or, if it’s not, make sure its Neutral property is set to true.
If both of those conditions aren’t met, then it won’t spawn the player on that RespawnLocation:
If RespawnLocation is not set to a valid SpawnLocation then the default spawning logic will apply. For more information on this see the page for SpawnLocation.
Ah, after doing some quick tests in Roblox Studio, it turns out that Player.RespawnLocation only works when it’s set by the server. There are other ways of retrieving JoinData, including through Player:GetJoinData(), so it’d be possible to slightly modify what you had in the original post to handle this from the server-side.
Although I did not test this in a live game when being teleported from another place, I simulated a similar setup by having the script randomly choose a value that is only associated with one spawnpoint and it successfully teleported the player to that spot right away upon join, as well as every time their Character respawned.
The example I created for testing purposes
local Players = game:GetService("Players")
local places = {
[1] = workspace:WaitForChild("SpawnLocation1"),
[2] = workspace:WaitForChild("SpawnLocation2"),
[3] = workspace:WaitForChild("SpawnLocation3")
}
Players.PlayerAdded:Connect(function(player)
local randomNumber = math.random(1,3)
player.RespawnLocation = places[randomNumber]
print(player.RespawnLocation)
end)
Here’s an example of how you could modify the code in the original post to be compatible with a Server Script:
Completed Example Revision (Server Script):
-- Server Script code
local Players = game:GetService("Players")
local place1Id = 128194721848749
local place2Id = 136403810915632
local place3Id = 133711048400377
local places = {
-- Update these to the intended SpawnLocations for each place
[place1Id] = workspace:WaitForChild("SpawnLocation1"),
[place2Id] = workspace:WaitForChild("SpawnLocation2"),
[place3Id] = workspace:WaitForChild("SpawnLocation3")
}
Players.PlayerAdded:Connect(function(player)
local joinData = player:GetJoinData()
local comingFromPlace = joinData.comingFromPlace
if comingFromPlace == nil then return end
player.RespawnLocation = places[joinData.comingFromPlace]
print(player.RespawnLocation)
end)
What ended up fixing it? If it wasn’t any of the things I explained, please explain what the solution was so that anyone else who encounters the same issue and reads through this thread in the future will know what solved it for your use case.