I am new to Datastore2, but I am using it for my soon to be released game.
I have a system where players can pay 25 R$ to play a song, and it is queued. This whole system works fine, however, I’m trying to make it so that if a server shuts down as an example, then when the player rejoins it re-queues their song. This is so that if I ever need to shut down all servers for something, I don’t have a riot of refund requests.
if #DJFolder:GetChildren() > 0 then --If there are queued songs
CustomSong = true
local Chosen = nil
local Lowest = math.huge
local Player
for _,v in pairs(DJFolder:GetChildren()) do
if v.PosValue.Value < Lowest then --Gets who is at the top of the queue
Chosen = v
Lowest = v.PosValue.Value
Player = v.PlayerValue.Value
end
end
pcall(function()
local queuedSongDataStore = DataStore2("QueuedSong",Player)
queuedSongDataStore:Set(0)
Player.DJ_ID.Value = 0
end)
PlaySound(Chosen)
Chosen:Destroy()
ShopEvent:FireAllClients("DJ_QueueUpdated")
else
local RndmTable = {}
if #CurrentSoundsFolder:GetChildren() <= 0 then
for i,Sound in pairs(SoundsTings:GetChildren()) do
local Clone = Sound:Clone()
Clone.Parent = CurrentSoundsFolder
end
end
for _,v in pairs(CurrentSoundsFolder:GetChildren()) do
table.insert(RndmTable,v)
end
RndmTable = shuffle(RndmTable)
local ChosenSound = RndmTable[math.random(1,#RndmTable)]
PlaySound(ChosenSound)
ChosenSound:Destroy()
end
Here is the section where I am planning to make it so that it tells the datastore that the player’s song has been played so that when they join a new server it doesn’t queue their song thinking an error occurred in the last one
My ultimate problem is that the Datastore module wants the player object, not the players UserId. So if a player is no longer in the game wouldn’t this cause an error? If anyone knows what I should do that would be appreciated thanks.