I am making a Pet System in my game, and I am working on making redeemable codes for the pets. However, I am always getting this error whenever I try to enter a code: Attempt to index nil with value.
Here’s the main script:
replicatedStorage.Remotes.RedeemCode.OnServerInvoke = function(player, code)
if code ~= nil then
if not player.Codes:FindFirstChild(code) then
local codeData = nil
for i, v in pairs(codesModule.Codes:GetChildren()) do
if v.Code == code then
codeData = v
break
end
end
if codeData ~= nil then
local codeVal = Instance.new("StringValue",player.Codes)
codeVal.Name = codeData.Code
return codeData.Pet
else
return "Invalid Code"
end
else
return "Already Redeemed"
end
end
end
Here’s the Codes Module:
local module = {}
module.Codes = {
Code1 = {Code = "NoobCode", Pet = "Noob Pet"}
}
return module