When using
:GetDataStore()
things save completely fine.
When using
:GetGlobalDataStore()
local Data = {} local Http = game:GetService("HttpService") -------- local DS = game:GetService("DataStoreService") local CodeDS = DS:GetGlobalDataStore("asdasd333334dsf") -------- local RepStorage = game:GetService("ReplicatedStorage") local ServerStorage = game:GetService("ServerStorage") function Data:CodeRedeemed(userId, code) wait() CodeDS:SetAsync(tonumber(userId).."_"..code, "Redeemed") warn'SET' end function setCodes(player, code) if Data:CheckIfRedeemedCode(player.userId, code) then warn'Code already redeemed' else Data:CodeRedeemed(player.userId, code) warn'Redeeming Code' end end function Data:CheckIfRedeemedCode(userId, code) if CodeDS:GetAsync(tonumber(userId).."_"..code) == "Redeemed" then return true else return false end end game.Players.PlayerAdded:connect(function(player) wait() if Data:CheckIfRedeemedCode(player.userId, "230-823-392") then warn'WHAT THE adsaddddddd' end end) game.ReplicatedStorage.code.OnServerEvent:connect(setCodes)
What am I doing wrong here?
You're calling a function too early, specifically the function setCodes in line 16 is calling CheckIfRedeemedCode.
function setCodes(player, code) if Data:CheckIfRedeemedCode(player.userId, code) then
However, in line 24...
function Data:CheckIfRedeemedCode(userId, code)
Functions that are deeper in the code can't be called by functions that are 'in the surface' of the code.
Lua isn't multi-threaded. It goes line by line. If it encounters a function not defined yet, it will break the whole script. Move the function CheckIfRedeemedCode to a line 16 or higher but below line 5 and the script might work again.