I am trying to make a way to save an IntValue that checks if the player owns an item or not. The issue is that when they buy the item and then rejoin the data doesn’t save and they do not own the item. I’ve never really succeeded that many times with data stores. I’ve tried changing it to a boolvalue but I got the same problem, however when I used a boolvalue they semt to always own the item.
--Server Script that sets up the item:
function CreateFF(player)
local knivesfolder = player:WaitForChild('knivesfolder')
local owns = Instance.new('IntValue')
owns.Parent = knivesfolder
owns.Name = 'FreezeKnife'
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Knives")
local DefaultData = {
owns = 0;
}
local Data = DataStore:GetAsync(tostring(player.UserId))
if Data then
owns.Value = Data
else
owns.Value = DefaultData.owns
end
end
-- Save Data
local function SaveData(player)
local owns = player.knivesfolder.owns.Value
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Knives")
DataStore:SetAsync(tostring(player.UserId), owns)
end
game.Players.PlayerRemoving:Connect(SaveData)
game.Players.playerAdded:Connect(CreateFF)
--Creates the knife folder: (note: this is a seperate script).
function CreateFF(player)
local knivesfolder = Instance.new("Folder")
knivesfolder.Parent = player
knivesfolder.Name = 'knivesfolder'
end
game.Players.playerAdded:Connect(CreateFF)
I also have a couple of scripts that run when the player buys the item that makes the ‘KnifeFreeze.Value’ 1.
Any help would be appreciated as I’ve been trying to figure this out but have never asked anyone for help about it. I have checked various threads on the devforum and haven’t gotten any answers that were functional. Any help is appreciated.