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

What's up with this CreatePlaceAsync strange occurance?

Asked by 7 years ago

before you ask, i've looked over the place templates so many times FOR SOME REASON, this is giving incorrect player limits like a template set to 1 maximum player has 10 maximum players and multiplayer, which has 5 maximum players, sometimes has 1 then sometimes has 10 and massive multiplayer, which is 50 max, sometimes has 1 and 10, but if someone else tries to join it puts them in a completely different server. this script is messy, majority of it is worked off of the wiki

local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
local CDR = "4"
local newPlaceId
game.Players.PlayerAdded:connect(function(plr)
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,659770656) then
        game.Lighting.RemoteEvent:FireClient(plr,"Owns50")
    end
end)

game.Lighting.RemoteEvent.OnServerEvent:connect(function(player,arg1,arg2)
    if arg1 == "ResetSingle" then
        local playerIdentity = player.Name
    local playerKey = 'Singleplayer_' .. player.userId.."_"..CDR
    local playerData = {
        SinglepersonalPlaceId = 0  
    }
    ds:SetAsync(playerKey, playerData)
    end
    if arg1 == "ResetMulti" then
        local playerIdentity = player.Name
    local playerKey = 'Multiplayer_' .. player.userId.."_"..CDR
    local playerData = {
        personalPlaceId = 0
    }
    ds:SetAsync(playerKey, playerData)
    end
    if arg1 == "ResetMass" then
        local playerIdentity = player.Name
    local playerKey = 'MassMultiplayer_' .. player.userId.."_"..CDR
    local playerData = {
        MassMultipersonalPlaceId = 0   
    }
    ds:SetAsync(playerKey, playerData)
    end
    if arg1 == "TpM" then
        local newPlaceId
            local playerIdentity = player.Name

    local playerKey = 'Multiplayer_' .. player.userId.."_"..CDR
    local playerData = ds:GetAsync(playerKey)

    if playerData then
        if playerData.personalPlaceId <= 0 then
            playerData = nil
        end
    end

    if not playerData then             
        newPlaceId = game:GetService("AssetService"):CreatePlaceAsync(playerIdentity.." Multiplayer Server", 654935011)

        playerData = {
            personalPlaceId = newPlaceId                   
        }

        ds:SetAsync(playerKey, playerData) 
        ds:SetAsync("PlaceOwner_"..newPlaceId,player.UserId)
        ds:SetAsync("PlaceType_"..newPlaceId,"Multiplayer")
        game:GetService('TeleportService'):Teleport(playerData.personalPlaceId, player)
    end        

    if playerData and playerData.personalPlaceId then  
        game:GetService('TeleportService'):Teleport(playerData.personalPlaceId, player)        
    end
    end
if arg1 == "TpMass" then
    local newPlaceId
            local playerIdentity = player.Name

    local playerKey = 'MassMultiplayer_' .. player.userId.."_"..CDR
    local DataMASS = ds:GetAsync(playerKey)

    if DataMASS then
        if DataMASS.MassMultipersonalPlaceId <= 0 then
            DataMASS = nil
        end
    end

    if not DataMASS then               
        newPlaceId = game:GetService("AssetService"):CreatePlaceAsync(playerIdentity.." Massive Multiplayer Server", 659753796)

        DataMASS = {
            MassMultipersonalPlaceId = newPlaceId                  
        }

        ds:SetAsync(playerKey, DataMASS)   
        ds:SetAsync("PlaceOwner_"..newPlaceId,player.UserId)
        ds:SetAsync("PlaceType_"..newPlaceId,"Multiplayer")
        game:GetService('TeleportService'):Teleport(DataMASS.MassMultipersonalPlaceId, player) 
    end        

    if DataMASS and DataMASS.MassMultipersonalPlaceId then 
        game:GetService('TeleportService'):Teleport(DataMASS.MassMultipersonalPlaceId, player)         
    end
    end
    if arg1 == "TpS" then
        local newPlaceId
            local playerIdentity = player.Name

    local playerKey = 'Singleplayer_' .. player.userId.."_"..CDR
    local DataSINGLE = ds:GetAsync(playerKey)

    if DataSINGLE then
        if DataSINGLE.SinglepersonalPlaceId <= 0 then
            DataSINGLE = nil
        end
    end

    if not DataSINGLE then             
        newPlaceId = game:GetService("AssetService"):CreatePlaceAsync(playerIdentity.." Singleplayer Mode", 655017845)

        DataSINGLE = {
            SinglepersonalPlaceId = newPlaceId                 
        }

        ds:SetAsync(playerKey, DataSINGLE)
        ds:SetAsync("PlaceOwner_"..newPlaceId,player.UserId)
        ds:SetAsync("PlaceType_"..newPlaceId,"Singleplayer")
        game:GetService('TeleportService'):Teleport(DataSINGLE.SinglepersonalPlaceId, player)  
    end        

    if DataSINGLE and DataSINGLE.SinglepersonalPlaceId then
        game:GetService('TeleportService'):Teleport(DataSINGLE.SinglepersonalPlaceId, player)          
    end
    end
    if arg1 == "Join" then
        local k =ds:GetAsync("PlaceType_"..tonumber(arg2))
        if k then
            if k == "Multiplayer" then
                game.Lighting.RemoteEvent:FireClient(player,"Destroy")
        game:GetService('TeleportService'):Teleport(tonumber(arg2), player)
            else print("Invalid. Not multiplayer server.")
            end
            else print("Invalid. Game not found.")
            end
    end

Answer this question