{"id":"lfg-studio/dailyrewards","name":"dailyrewards","scope":"lfg-studio","platform":"roblox","description":"Daily rewards system","version":"1.0.0","latest":"1.0.0","versions":["1.0.0"],"license":"Apache-2.0","licenseRating":"safe","licenseCaveats":["Modified files must carry a notice of changes. If the package ships a NOTICE file, its attributions must be preserved."],"licenseVerified":true,"dependencies":{"sleitnick/signal":{"version":"^2.0.1","alias":"Signal"}},"integrity":"b3985dcebd477f2695cf815d5afa85b740d4a59320a41cfad4eadb5bbb443fb5","likes":0,"downloads":0,"install":"forest install lfg-studio/dailyrewards","url":"https://forest.dev/p/roblox/lfg-studio/dailyrewards","files":"https://api.forest.dev/ai/package/roblox/lfg-studio/dailyrewards/files","readme":"# Daily Rewards\n\n### Setting up the UI\nDownload the [daily-rewards-template.rbxm](./daily-rewards-template.rbxm) file from the repository and import it into Roblox Studio.\nThis template contains the necessary UI elements for the daily rewards system.\n\n### Installing the wally dependency\nAdd the below line to your wally.toml file\n```toml\nDailyRewards = \"Looking-Fresh-Games/DailyRewards@1.0.0\"\n```\n\nWhat to track on the server for each player:\n- Claim streak (default to 0)\n- Time of last claim (default to 0)\n\n### Setting up the rewards\n```lua\nlocal DailyRewardData = {\n\t[1] = {\n\t\tlabel = \"+10 Cash\",\n\t\ticon = \"rbxassetid://117582891502895\",\n\t\trewardType = \"coins\",\n\t\tvalue = 10,\n\t},\n\t[2] = {\n\t\tlabel = \"+50 Cash\",\n\t\ticon = \"rbxassetid://18209599044\",\n\t\trewardType = \"coins\",\n\t\tvalue = 50,\n\t},\n\t[3] = {\n\t\tlabel = \"Knife Skin\",\n\t\ticon = \"rbxassetid://7660845823\",\n\t\trewardType = \"skin\",\n\t\tvalue = \"Golden\",\n\t},\n\t-- and so on\n}\n```\n\nNote: Each day reward defined in `DailyRewardData` should have it's own frame in `DailyRewards.Wrap.List`\n\n(example: `DailyRewards.Wrap.List.1`, `DailyRewards.Wrap.List.2`, `DailyRewards.Wrap.List.3`, etc.)\n\nEach day frame should also contain:\n- A `Label` for the reward name named \"Label\"\n- An `ImageLabel` for the reward icon named \"Icon\"\n- A `TextLabel` named \"Label\" insde a `Frame` named \"Lock\" to indicate which day streak the reward is for.\n\nThese labels and icons will be set depending on the data you provide in `DailyRewardData`.\n\n### Initiating the client\n```lua\nlocal DailyRewards = require(Packages.DailyRewards)\n\nlocal profileData = getProfileData() -- Replace with your data fetcher\n\nDailyRewards.initClient({\n\tscreenGui = game.Players.LocalPlayer.PlayerGui.DailyRewards,\n\n\t-- New players should default to 0 for both values\n\tclaimedDays = profileData.claimedDays,\n\tlastClaim = profileData.lastClaimTime or 0,\n\n\tdata = DailyRewardData\n})\n```\n\n### Handling claim requests on the server\nThe `rewardType` and `value` fields in the `DailyRewardData` table are used to determine what reward to give the player.\nThey can be set to any value you want.\n\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\n\nlocal DailyRewards = require(Packages.DailyRewards)\n\nlocal DailyRewardData = require(ReplicatedStorage.Shared.Data.DailyRewardData)\n\nDailyRewards.initServer(DailyRewardData) -- Must initialize the rewards system by passing the reward data\n\n-- \"PlayerClaimRequest\" is a signal that fires when a player requests\n-- to claim a reward using the Claim button in the daily rewards UI.\nDailyRewards.PlayerClaimRequest:Connect(function(\n\tplayer: Player,\n\tdayData: DailyRewards.DayData,\n\tday: DailyRewards.Day,\n\tclaimTime: number\n)\n\tlocal playerData = DataService:GetData(player)\n\n\tif not playerData then\n\t\treturn\n\tend\n\n\t-- Check if the player can claim the reward\n\tlocal canClaim: boolean = DailyRewards.canClaim(day, playerData.LastClaim, playerData.ClaimedDays)\n\n\tif not canClaim then\n\t\treturn\n\tend\n\n\t-- Give the player the reward\n\tplayerData.ClaimedDays = day\n\tplayerData.LastClaim = claimTime\n\n\t-- Handle awarding the reward based on the `rewardType` and `value` fields\n\tif dayData.rewardType == \"coins\" then\n\t\tplayerData.Coins += dayData.value :: number\n\tend\nend)\n```\n\n## Signals\nYou can listen to the following signals to handle events in your game.\n\n### Server\n\n---\n`DailyRewards.PlayerClaimRequest :: Signal.Signal<player: Player, dayData: DailyRewards.DayData, streak: number, claimTime: number>`\n\nThe `PlayerClaimRequest` signal is fired when a player requests to claim a reward using the Claim button in the daily rewards UI.\n\nUse the `DailyRewards.canClaim` function to validate their claim request.\n\n```lua\nlocal DailyRewards = require(Packages.DailyRewards)\n\nDailyRewards.PlayerClaimRequest:Connect(function(\n\tplayer: Player,\n\tdayData: DailyRewards.DayData,\n\tday: DailyRewards.Day,\n\tclaimTime: number\n)\n\tlocal playerData = DataService:GetData(player)\n\n\tif playerData then\n\t\t-- Check if the player can claim the reward\n\t\tlocal canClaim: boolean = DailyRewards.canClaim(day, playerProfile.lastClaimTime, playerProfile.claimedDays)\n\n\t\tif canClaim then\n\t\t\tprint(`{player.Name} can claim the reward!`)\n\n\t\t\t-- Save the `claimTime` and `day` values to the player's data\n\t\t\t-- to track their claim streak\n\t\t\t-- and then award the player with the daily reward\n\t\tend\n\tend\nend)\n```\n\n---\n\n### Client\n\n---\n\n`DailyRewards.Claimed :: Signal.Signal<streak: number, dayData: DailyRewards.DayData>`\n\nUse the `Claimed` signal to handle the reward claim on the client side or any special effects you want to trigger when a player claims a reward.\n\n---\n\n`DailyRewards.VisibilityChanged :: Signal.Signal<visible: boolean>`\n\nThe `VisiblityChanged` signal is useful for handling state changes in the UI, such as highlighting a daily rewards button when the UI is open.\n\n---\n","readmeTruncated":false}