So I'm having troubles with data stores despite the print debugging method working fully through. There seem to be no errors in output either. The script is in a folder in ServerScriptService.
local DSService = game:GetService("DataStoreService"):GetDataStore("KytesSave")
local PlayersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
PlayersLeft = PlayersLeft + 1
local Kytes = Instance.new("IntValue")
Kytes.Name = "Kytes"
Kytes.Value = 0
Kytes.Parent = player
local player_data
pcall (function()
player_data = DSService:GetAsync(player.UserId.."-Kytes")
end)
if player_data ~= nil then
Kytes.Value = player_data
else
Kytes.Value = 0
end
end)
local bindableEvent = Instance.new('BindableEvent')
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
DSService:SetAsync(player.UserId..'-Kytes', player.Kytes.Value)
print("Saved")
PlayersLeft = PlayersLeft - 1
bindableEvent:Fire()
end)
end)
game:BindToClose(function()
while PlayersLeft > 0 do
bindableEvent.Event:Wait()
end
end)

4 comments
What is it your trying to save? I don't understand.... Please explain what you are trying to do
I'm trying to save the "Kytes" value, the currency of the game.
On line #26 {player.Kytes.Value}, On Line #16 {player_data[1]}
Pretty sure Datastore only accepts tables and not values