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

Why is this line of code wont save your spot when you leave and rejoin and make you at start?

Asked by 4 years ago

I was watching a tortorial and the scripts didnt work and i cant find new ones and im despreate. First i put the teams and make spawns that act like checkpoints. I add this scrpit in ServerScriptService.

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ObbbyDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local data
    local success, errorMessage = pcall(function()
        data = DataStore:GetAsync(player.UserId.."-stage")
    end)

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

    player:LoadCharacter()

end)

game.Players.PlayerRemoving:Connect(function(player)
    local teamName = player.Team.Name
    local success, errorMessage = pcall(function()
        DataStoreService:SetAsync(player.UserId.."-stage",teamName)
    end)

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

And another script that has this code:

local checkpoints = game.Workspace:WaitForChild("Checkpoints"):GetChildren()

for i, checkpoint in pairs(checkpoints) do
    checkpoint.TeamColor = game.Teams:FindFirstChild(checkpoint.Name).Teamcolor
    checkpoint.BrickColor = game.Teams:FindFirstChild(checkpoint.Name).Teamcolor
end

1 answer

Log in to vote
1
Answered by 4 years ago

Watch the rest of AlvinBlox's video xD

0
i got it lol ivan6361 34 — 4y
Ad

Answer this question