Training hub script

Now, I saw a post asking how to script a Training Hub

Now. Here is a link about it, The script might be in there?

Training Hub Script- Devfourm

I haven’t checked this script yet. But you guys can tell me if it worked <3

Script:

so first of all to check if the player is in the group and that rank or above to this

 if  Player:GetRankInGroup(groupid) >= 235 then
print("Player has required rank!")
end 

For creating the “Private Server” you should use TeleportService:ReserveServer on a server script by using a remote event (make sure to check if they are the correct rank on the server!

Then you can use DataStoreService to store the Reserved Server Codes and read them.

For example you would do something like this on the server

local TeleportService = game:GetService("TeleportService")
local PlaceId = 0 --Must be apart of the universe
local UpdateTime = 15
local DataStoreService = game:GetService("DataStoreService")
local options = Instance.new("DataStoreOptions")
options.AllScopes = true
local ReservedServers = DataStoreService:GetDataStore("Servers","",options)

RemoteEventToMakeAServer.OnServerEvent:Connect(function(Plr,data) 
	if  Player:GetRankInGroup(groupid) >= 235 then
		print("Player has required rank!")
		local ReservedServerCode = TeleportService:ReserveServer(PlaceId)
	

	
		ReservedServers:SetAsync(ReservedServerCode,{Name  = data.Name,Plrs = {},Creator = Plr.UserId})
		
		TeleportService:TeleportToPrivateServer(PlaceId,ReservedServerCode,{Plr},nil,ReservedServerCode)
	end
end)

RemoteEventToJoinAServer.OnServerEvent:Connect(function(Plr,ReservedServerCode) 
		ReservedServers:SetAsync(ReservedServerCode,"")
		
		TeleportService:TeleportToPrivateServer(PlaceId,ReservedServerCode,{Plr})
end)


while wait(UpdateTime) do
	local Servers = {}
	local listSuccess, pages = pcall(function()
		return ReservedServers:ListKeysAsync()
		
	end)
	
	if listSuccess then
		while true do
			local items = pages:GetCurrentPage()
			for _, v in ipairs(items) do
				table.insert(Servers,v.KeyName)
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
		end
	end
	
	RemoteEventToSendServersToClient:FireAllClients(Servers)
end

On the client you would put something like this

ButtonToMakeServer.MouseButton1Click:Connect(function()
  RemoteEventToMakeAServer:FireServer({Name = textboxNameofServerInput .Text})
end)

RemoteEventToSendServersToClient.OnClientEvent:Connect(function(Servers) 
    -- make sure to clear the server list frame here
    for i,Data in pairs(Servers) do 

     local Name = Data.ServerData.Name
     local PlayerList = Data.ServerData.Plrs
     local  ReserveServerCode = Data.ReservedServerCode

     -- make the ui stuff

      button.MouseButton1Click:Connect(function() 
        RemoteEventToJoinAServer:FireServer(ReserveServerCode)
     end
     end

end)

Now on the training servers have something like this under a server script

local Http = game:GetService("HttpService")
local ReserveServerCode = ""
local GotReserveServerCode = false
local UpdateInterval = 15
local DataStoreService = game:GetService("DataStoreService")
local options = Instance.new("DataStoreOptions")
options.AllScopes = true
local ReservedServers = DataStoreService:GetDataStore("Servers","",options)
local ReservedServer

game.Players.PlayerAdded:Connect(function(player) 
	if not GotReserveServerCode  then 
		if player:GetJoinData().TeleportData then
			GotReserveServerCode   = true
			ReserveServerCode = player:GetJoinData().TeleportData
                      ReservedServer =  Http:JSONDecode(ReservedServers:GetAsync(ReserveServerCode))

		end
	end
end)

-- All we need to do next is update the player list

while wait(UpdateInterval ) do
       local Players  = game:GetService("Players")
        local UserIdTable = {}
      for i,v in pairs(Player:GetPlayers) do
       table.insert(UserIdTable,v.UserId)
      end

      ReservedServers:SetAsync(ReserveServerCode,Http:JSONEncode({Name  = ReservedServer.Name, Plrs = UserIdTable, Creator = ReservedServer.Creator})
end

-- Now when the game closes we remove the Server
   

game:BindToClose(function()
	ReservedServers:RemoveAsync(ReserveServerCode)
end)

again, i got this code from this devfourm post

What’s the problem you have?

(post deleted by author)

hi! sorry. i accidently put this on the wrong topic. i just fixed it

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.