I’m trying to make it so where multiple players can go into a private server without creating a new one.
It is throwing an error at me.
Can’t find any related posts.
Code
local DataStoreService = game:GetService("DataStoreService")
local Servers = DataStoreService:GetDatastore("Servers")
-- This is not the full code I just added the variables above me to make it easier to understand.
local Server = Servers:GetAsync(Map) or "No Map"
if Server then
TeleportService:TeleportToPrivateServer(8233496538,Server,{Player},"SpawnLocation",Map)
else
local Success,Error = pcall(function()
Servers:UpdateAsync(Map,ReserveServer)
end)
if Success then
Server = Servers:GetAsync(Map) or "No Map"
print(Server)
TeleportService:TeleportToPrivateServer(8233496538,Server,{Player},"SpawnLocation",Map)
else
print(Error)
end
end
Another Game that’s inside a Game, I don’t know how to explain it but, the Game itself has no problems, I could teleport there no problem until I added Datastores.
So, it’s basically a place that’s within the game’s universe then
The only thing I’d probably check is printing out what Servers/Server is and see where the script exactly stops, and I believe UpdateAsync requires you to return the value that you’re attempting to obtain
Either that or the game you’re attempting to teleport to is restricted
Ok, tried that, turns out UpdateAsync has nothing to do with the problem. Just figured out that GetAsync doesnt work even though it changed the value (It prints “No Map”), and I’ve got a new error: Transform function error Callbacks cannot yield.
New Code
local DataStoreService = game:GetService("DataStoreService")
local Servers = DataStoreService:GetDatastore("Servers")
function ReserveServer(x,y)
return TeleportService:ReserveServer(8233496538)
end
-- Events
Teleport.OnServerEvent:Connect(function(Player,Map)
local Server = Servers:GetAsync(Map) or nil
if Server then
print(Server)
TeleportService:TeleportToPrivateServer(8233496538,Server,{Player},"SpawnLocation",Map)
else
local Success,Error = pcall(function()
print(Server)
Servers:UpdateAsync(Map,ReserveServer)
end)
if Success then
print(Server)
Server = Servers:GetAsync(Map) or "No map"
print(Server)
TeleportService:TeleportToPrivateServer(8233496538,Server,{Player},"SpawnLocation",Map)
else
print(Error)
end
end
end)
local Success, Error = pcall(function()
print(Server)
Servers:UpdateAsync(Map, function(NewValue)
return TeleportService:ReserveServer(NewValue) --Or what it is you're trying to reserve
end)
end)
The solution was a little bit different, but using UpdateAsync that way gave me an idea.
Here’s the code for anybody having the same problem:
Code
local DataStoreService = game:GetService("DataStoreService")
local Servers = DataStoreService:GetDataStore("Servers")
local PlaceId = 8233496538
-- Events
Teleport.OnServerEvent:Connect(function(Player,Map)
local Server = Servers:GetAsync(Map) or nil
if Server then
print(Server)
TeleportService:TeleportToPrivateServer(PlaceId,Server,{Player},"SpawnLocation",Map)
else
local Success,Error = pcall(function()
print(Server)
local Code = TeleportService:ReserveServer(PlaceId)
Servers:UpdateAsync(Map,function(x)
return Code
end)
end)
if Success then
print(Server)
Server = Servers:GetAsync(Map) or "No map"
print(Server)
TeleportService:TeleportToPrivateServer(PlaceId,Server,{Player},"SpawnLocation",Map)
else
print(Error)
end
end
end)