Roblox Guide Help

Daily Rewards Module

In your wally.toml file, add this to your dependencies:

[dependencies] dailyrewards-module = "release/dailyrewards-module@0.0.1"

You have two solutions to import this module, depending if you wish to import the Controller or the Service on your own, or if you let the module give you the right code.

local DailyRewardsModule = require(ReplicatedStorage.Packages["dailyrewards-module"]) -- Serves for initialization for both the controller and -- the service depending where it's called.
local DailyRewardsService = Knit.GetService("DailyRewardsService")
local DailyRewardsController = Knit.GetController("DailyRewardsController")

Configuration

A file called DailyRewardsModule.config.lua is to be created in ReplicatedStorage/Shared/Configs.

return table.freeze({ ClaimCooldown = 86400, -- In seconds RewardList = { [1] = { Item = "Pet1", Amount = 1, Type = "Item" }, [2] = { Item = "Wins", Amount = 150, Type = "Currency" } } })

Explanation:

  • ClaimCooldown: The amount of time between each claim (in seconds). Example is 24 hours (The default)

  • RewardList: A list of rewards

    • Item: The name of the item / currency to give

    • Amount: The amount of the item / currency to give

    • Type: The type of item to give (Can be anything, it depends on the rest of the code)

Usage

Events

  • OnPlayerClaim: Triggers when the player claims an item.

Methods

Shared

Explanation

  • player: The player to check the status of.


local lastTimeClaimed = DailyRewardsService:GetLastTimeClaimed(player) print(lastTimeClaimed)

local canPlayerClaim = DailyRewardsService:CanPlayerClaim(player) if canPlayerClaim then print("Player can claim !") end

    Client Side

    Explanation


    local timeLeftBeforeNextReward = DailyRewardsController:GetFormattedTime() UI.Button.Text = "Time left is: "..timeLeftBeforeNextReward

      Client Side

      Explanation

      • player: The player trying to claim.


      if canPlayerClaim then DailyRewardsService:Claim(player) end
        Last modified: 17 December 2024