So, I have a function to manage datastores in a module script that works with remote events. Right now, if I do GetAsync
it returns nil and not the value wanted. Anyone have any ideas on why this is happening? I’ve looked around devforum and google a bit but can’t find a solution.
local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events", WaitForTimeout):WaitForChild("1", WaitForTimeout)
local DatastoreService = game:GetService("DataStoreService")
local Datastore = DatastoreService:GetDataStore("Coins")
local Connection
Connection = Event.OnServerEvent:Connect(function(Player, Key, Action, Value)
warn(Player, Key, Action, Value)
local Success, Response = pcall(function()
if Action == "GetAsync" then
Event:FireClient(Player, Datastore:GetAsync(Player.UserId.."_"..DatastoreName))
task.wait()
elseif Action == "IncrementAsync" then
Datastore:IncrementAsync(Player.UserId.."_"..DatastoreName, Value)
task.wait()
elseif Action == "SetAsync" then
Datastore:SetAsync(Player.UserId.."_"..DatastoreName, Value)
task.wait()
end
end)
if not Success then
warn(Response)
end
task.wait()
Connection:Disconnect()
end)