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

Value not being created, and other value being created as intvalue?

So im making a datastore that saves the players leaderstats data but for some reason its not working. Because for some unknown reason the AFKTime value is not being created. and my Rank Value is being created as a integer value rather then a stringvalue

Code: (Server script in ServerScriptService)

local DataStoreService = game:GetService("DataStoreService")
local AFKTimeData = DataStoreService:GetDataStore("AFKTimeData")





game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"
	
	local AFKTime = Instance.new("IntValue")
	AFKTime.Parent = leaderstats
	AFKTime.Name = "AFKTime"
	AFKTime.Value = 0
	
	local Rank = Instance.new("StringValue")
	AFKTime.Parent = leaderstats
	AFKTime.Name = "Rank"
	AFKTime.Value = "Active"
	
	local PlayerId = "Player_"..player.UserId
	
	-- Data Loading System
	
	local data
	local success, errormessage = pcall(function()
		data = AFKTimeData:GetAsync(PlayerId)	
		
	end)
	
	if success then
		AFKTime.Value = data.AFKTime
		Rank.Value = data.Rank
	else
		print("An Error occurred")
		warn(errormessage)
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
		local PlayerId = "Player_"..player.UserId
	
	local data = {
		AFKTime = player.leaderstats.AFKTime.Value,
		Rank =	player.leaderstats.Rank.Value
	}
	local success, errormessage = pcall(function()
		AFKTimeData:GetAsync(PlayerId, data)
	end)
	
	if success then
		print("Data Successfully saved")
	else
		print("An Error occurred while saving data")
		warn(errormessage)
	end

end)

1 answer

✓ Accepted answer

Between lines 19 and 22, you use the wrong variable.

1 comment

0

oh

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