Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I Cant Get Saves To Work (AlvinBlox Tutorial) Help?

So, i was following a tutorial by Alvin Blox (https://www.youtube.com/watch?v=tFATXcfL4zs&t=8s) and the saves don't seem to work. There are no errors it just doesn't work. Can I have some help?

(Stats Script)


local serverStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave")

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local strength = Instance.new("NumberValue")
	strength.Name = "Strength"
	strength.Parent = leaderstats
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats 
	
	local dataFolder = Instance.new("Folder")
	dataFolder.Name = player.Name
	dataFolder.Parent = serverStorage.RemoteData
	
	local debounce = Instance.new("BoolValue")
	debounce.Name = "Debounce"
	debounce.Parent = dataFolder
	
	local strengthData, rebirthsData
	
	local success,errormessage = pcall(function()
		strengthData = DataStore:GetAsync("Strength-"..player.UserId)
		rebirthsData = DataStore:GetAsync("Rebirths-"..player.UserId)
	end)
	if success then
		if strengthData then
			strength.Value = strengthData
			rebirths.Value = rebirthsData
		end
	end
	
	
end)
game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DataStore:SetAsync("Strength-"..player.UserID,player.leaderstats.Strength.Value)
		DataStore:SetAsync("Rebirths-"..player.UserID,player.leaderstats.Rebirths.Value)
	end)
end)

if there is other code that needs to be seen just tell me, thank you in advance.

1 answer

The problem is line 41 - 46 if you look there, you mispelled UserId.

local serverStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave")

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

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local strength = Instance.new("NumberValue")
    strength.Name = "Strength"
    strength.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Parent = leaderstats 

    local dataFolder = Instance.new("Folder")
    dataFolder.Name = player.Name
    dataFolder.Parent = serverStorage.RemoteData

    local debounce = Instance.new("BoolValue")
    debounce.Name = "Debounce"
    debounce.Parent = dataFolder

    local strengthData, rebirthsData

    local success,errormessage = pcall(function()
        strengthData = DataStore:GetAsync("Strength-"..player.UserId)
        rebirthsData = DataStore:GetAsync("Rebirths-"..player.UserId)
    end)
    if success then
        if strengthData then
            strength.Value = strengthData
            rebirths.Value = rebirthsData
        end
    end


end)
game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        DataStore:SetAsync("Strength-"..player.UserID,player.leaderstats.Strength.Value)--Replace UserID with UserId
        DataStore:SetAsync("Rebirths-"..player.UserID,player.leaderstats.Rebirths.Value)--Replace UserID with UserId
    end)
end)

2 comments

0

Thank you so much! That solved it right away!

0

Can you mark my answer as correct?

This discussion is preserved as it was. New answers, comments, and votes are closed.