I made a code redeeming system but it returns invalid code no matter what.
I tried looking for solutions but I couldn’t find one
I think it’s an issue with the table.find but I don’t know what else to use
Code:
local badgeCodeDictionary = {
[661262958584740] = "OOPSsoSILLY",
[3784587926611516] = "SOEVIL",
[984651461585313] = "iHEARTducks"
}
local codes = {
["RELEASE"] = 100,
["OOPSsoSILLY"] = 50,
["SOEVIL"] = 40,
["iHEARTducks"] = 30
}
game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(plr,code)
if table.find(badgeCodeDictionary,code) then
if game.BadgeService:UserHasBadgeAsync(plr.UserId,table.find(badgeCodeDictionary,code)) then
plr.leaderstats.Coins += codes[code]
return("Redeemed!")
else
return("You don't own the badge!")
end
elseif table.find(codes,code) then
plr.leaderstats.Coins += codes[code]
return("Redeemed!")
else
return("Invalid code!")
end
end
The code on the client (if it helps):
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Text = "Redeeming.."
local text = game.ReplicatedStorage.RedeemCode:InvokeServer(script.Parent.Parent.TextBox.Text)
script.Parent.Text = text
task.wait(3)
script.Parent.Text = "Redeem"
end)
I think the badge service doesnt work in Roblox Studio but i might be wrong idk. And also i want to add that you dont remove the codes from the table meaning they can be redeemed multiple times.
print(game:GetService("BadgeService"):UserHasBadgeAsync(game.Players.LocalPlayer.UserId, 2983459406401754)) -- The badge I got 15 mins ago from a game
They probably shouldn’t do that since it’s a server script, if they did other players in the server wouldn’t be able to redeem after one player did, if you’ve written that looking at my response, I forgot to delete what I was testing on a localscript since I didn’t want to deal with RemoteFunctions lol.
You can simply use tables but that wouldn’t save globally, so let’s say if the player left and joined another server they could be able to redeem the same code again. Use Data Stores instead to save data globally like redeemed codes and in-game earned currencies.