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

How can i make my save spawnpoint script work?

Asked by 3 years ago
Edited 3 years ago
local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("ObbyDataStore")

game.Players.PlayerAdded:Connect(function(player)

    local data

    local success, errorMessage = pcall(function()
        data = DataStore:SetAsync(player.UserId.."-stage")
    end)    

    if success then
        print("Success")
        if data then
            player.Team = game.Teams[data]      
        else 
            player.Team = game.Teams.Lobby 
        end
    else
        print(errorMessage)
        player.Team = game.Teams.Lobby 
    end

    player:LoadCharacter()

end) 

game.Players.PlayerRemoving:Connect(function(player)

    local teamName = player.Team.Name

    local success, errorMessage = pcall(function()
        DataStore:SetAsync(player.UserId.."-stage",teamName)
    end)    

    if success then
        print("All went well")
    else
        print(errorMessage)
    end
end)

I followed this tutorial to save spawnpoints in my obby game but it does not work. Does anyone know why?

There are no errors in the output.

Answer this question