Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local CodesConfig = require(ReplicatedStorage.Configs.Codes)
- local Remotes = ReplicatedStorage.Remotes
- local function RedeemCode(Player: Player, CodeName: string)
- local GivenCode = string.lower(CodeName)
- local FoundCode = nil
- for _, Code in ipairs(CodesConfig) do
- if string.lower(Code.CodeName) == GivenCode then
- FoundCode = Code
- break
- end
- end
- if not FoundCode then
- return false, "Code Invalid"
- end
- local CurrentTime = os.time()
- if CurrentTime > FoundCode.Expire then
- return false, "Code Expired"
- end
- if Player:FindFirstChild("RedeemedCodes"):FindFirstChild(FoundCode.CodeName) then
- return false, "Code Already Redeemed"
- end
- local Leaderstats = Player:FindFirstChild("leaderstats")
- if Leaderstats and Leaderstats:FindFirstChild(FoundCode.CurrencyType) then
- local CurrencyValue = Leaderstats[FoundCode.CurrencyType]
- CurrencyValue.Value += FoundCode.AmountToGive
- local RedeemedCode = Instance.new("StringValue", Player.RedeemedCodes)
- RedeemedCode.Name = FoundCode.CodeName
- return true, "Code Redeemed"
- else
- return false, "Failed To Reward"
- end
- end
- Remotes.RedeemCode.OnServerEvent:Connect(function(Player: Player, CodeName: string)
- if type(CodeName) ~= "string" then return end
- local Success, Message = RedeemCode(Player, CodeName)
- Remotes.RedeemCode:FireClient(Player, Success, Message)
- end)
Advertisement
Add Comment
Please, Sign In to add comment