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

Why doesnt my script save or load the values?

Made this huge script but it doesnt save or load the values

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

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

--Crear a leaderboard

local look = Instance.new("Model",player)
look.Name = "Clothes"

local Hair = Instance.new("IntValue",player.Clothes)
Hair.Name = "Hair"	

local Wearing = Instance.new("IntValue",player.Clothes)
Wearing.Name = "Shirt"

local Face = Instance.new("IntValue",player.Clothes)
Face.Name = "Face"

local CheckPoint = Instance.new("IntValue",player.Clothes)
CheckPoint.Name = "CheckPoint"

local SkinColor = Instance.new("IntValue",player.Clothes)
SkinColor.Name = "SkinColor"

local Sound = Instance.new("IntValue",player.Clothes)
Sound.Name = "Sound"

-- Buscar os dados do player

local key = "player-"..player.userId

local savedV = DataStore:GetAsync(key)

if savedV then
-- {This table assigns all aspects from your look}
 Hair.Value = savedV[1]
 Wearing.Value = savedV[2]
 Face.Value = savedV[3]
 CheckPoint.Value = savedV[4]
 SkinColor.Value = savedV[5]
 Sound.Value = savedV[6]
else
	local valuesToSave = {Hair.Value, Wearing.Value,Face.Value,CheckPoint.Value,SkinColor.Value,Sound.Value}
	DataStore:SetAsync(key, valuesToSave)
end

end)

game.Players.PlayerRemoving:connect(function(player)
	
	local key = "player-"..player.userId
	local valuesToSave = {player.Clothes.Hair.Value, player.Clothes.Wearing.Value, player.Clothes.Face.Value, player.Clothes.CheckPoint.Value, player.Clothes.SkinColor.Value, player.Clothes.Sound.Value}
	DataStore:SetAsync(key, valuesToSave)
	
end)

3 comments

0

connect is depricated use Connect -->> just saying

0

I recommend saving a JSON table using JSONEncode, and then use JSONDecode when you want to view it. It saves space, so you can store more in a string instead of a table.

0

Also, I've used :connect and it still works.

1 answer

In the if savedV then, the else will run only if they haven't played the game before so in the if set the values to either nothing or what they should be. If it isn't saving then the reason is because you never gave the clothes values in another script, so when it saved it saved blank values.

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