Hello! I am having an error. Every time that I send in the proper code, I always get the "Code Failed" to return. I even copy and paste the code to the same result. I am not sure why it is doing this, and will try using the print function to debug.
Server Script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("PromoCodes")
local BonusFunction = Instance.new("RemoteFunction")
BonusFunction.Name = "BonusFunction"
BonusFunction.Parent = game.ReplicatedStorage
local PlayerData = nil
local PromoCodes = {
["MLyPtHQvSoPq"] = false,
["YJW9vey8u6ud"] = false,
["G9oh5RDjH3TM"] = false
}
function BonusFunction.OnServerInvoke(Player, Code)
if DataStore:GetAsync(Player.userId) ~= nil then
PlayerData = DataStore:GetAsync(Player.userId)
else
DataStore:SetAsync(Player.userId, PromoCodes)
PlayerData = PromoCodes
end
for i, v in pairs(PromoCodes) do
if i == Code then
for g, c in pairs(PlayerData) do
if g == Code and c == false then
return "Code Succussful"
elseif c == true then
return "Code Used"
end
wait()
end
end
wait()
end
return "Code Failed"
end
Nothing is going wrong with the Local script.

1 comment
Although I'm still going over this, one thing you should immediately take note off is the fact that the function returned 'Code Failed' without any error. This means your conditional statements aren't being met in the for loops. It'd be useful to know how exactly you are invoking this function from the LocalScript