Giftoin Docs
  • 👋INTRODUCTION
    • Welcome to Giftoin
    • Overview
    • Quick Start
    • FAQs
    • Key Features
  • 🧩API REFERENCE
    • Standards and Conventions
    • Orders API
      • Tokens/Points
      • Collectibles/Cards
      • Collectibles/Random Cards
    • Users API
      • Inventory
      • Progress
    • Error Handling
  • 💻PLATFORM GUIDES
    • Roblox
      • Why use Giftoin?
      • Basic Usage
      • Developer Access
      • Installation
      • Additional Example / Use-Cases
        • Point Reward
        • Daily Reward
        • Advanced Point Distribution System
        • Managed Codes & In-Game Rewards (Coming Soon)
          • Registering Reward Types
      • Tools and Scripts
        • Rotating Script
        • Floating Script
        • Quest System (Coming Soon)
    • Discord
      • Introduction
      • Getting Started
      • Command Reference
      • Role System
      • User Guides
      • Troubleshooting
      • FAQs
    • Wordpress
  • 📚Resources
    • Use Cases
      • Basic
      • eCommerce
      • Games
    • Support
Powered by GitBook
On this page

Was this helpful?

  1. PLATFORM GUIDES
  2. Roblox
  3. Additional Example / Use-Cases

Point Reward

Here's an example of how to use the Giftoin Module to send points to a player when they join the game.

Server Script Example

Place this script in ServerScriptService:

-- Require the necessary modules
local GiftoinApi = require(game.ReplicatedStorage.GiftoinModule.API)
local GiftoinUtils = require(game.ReplicatedStorage.GiftoinModule.Utils)
local GiftoinEvents = require(game.ReplicatedStorage.GiftoinModule.Events)

-- Configuration (replace with your actual values)
local CAMPAIGN_ID = "your_campaign_id_here"
local POINT_ID = "your_point_id_here"
local JOIN_REWARD_AMOUNT = 100

-- Function to send points when a player joins
local function onPlayerJoin(player)
    local robloxId = tostring(player.UserId)
    
    -- Send points to the player
    local success, result = GiftoinApi.sendPoint(robloxId, CAMPAIGN_ID, POINT_ID, JOIN_REWARD_AMOUNT)
    
    if success then
        print(player.Name .. " was awarded " .. JOIN_REWARD_AMOUNT .. " points for joining!")
    else
        warn("Failed to send points to " .. player.Name .. ". Error: " .. tostring(result))
    end
end

-- Connect the function to the PlayerAdded event
game.Players.PlayerAdded:Connect(onPlayerJoin)

-- Set up the ClaimGiftoin event handler
local claimGiftoinEvent = game.ReplicatedStorage.GiftoinModule.ClaimGiftoinEvent

claimGiftoinEvent.OnServerEvent:Connect(function(player)
    -- Example of using sendPoint for a different scenario
    local success, result = GiftoinApi.sendPoint(tostring(player.UserId), CAMPAIGN_ID, "daily_reward", 50)
    
    if success then
        print(player.Name .. " claimed their daily reward of 50 points!")
    else
        warn("Failed to send daily reward points to " .. player.Name .. ". Error: " .. tostring(result))
    end
end)

Explanation

  1. We start by requiring the necessary modules from the GiftoinModule.

  2. We define configuration variables for the campaign ID, point ID, and the amount of points to award when joining. You should replace these with your actual values (from you Giftoin Dashboard website).

  3. The onPlayerJoin function is defined to send points to a player when they join. It uses GiftoinApi.sendPoint() with the following parameters:

    • robloxId: The player's Roblox User ID as a string

    • campaignId: The ID of your campaign

    • pointId: The ID of the point type you're awarding

    • quantity: The number of points to award

  4. We connect the onPlayerJoin function to the PlayerAdded event, so it runs whenever a new player joins the game.

  5. We also set up an event handler for the ClaimGiftoinEvent. This demonstrates how to use the sendPoint function in a different scenario, such as awarding daily rewards that will be explained in more detail in the section.

Important Notes

  • Make sure to replace "your_campaign_id_here" and "your_point_id_here" with your actual campaign and point IDs.

  • The robloxId is obtained from the player's UserId and converted to a string, as required by the sendPoint function.

  • Error handling is implemented to log any issues with sending points.

  • This example assumes that the sendPoint function returns a success boolean and a result. Adjust the error handling if the function behaves differently.

PreviousAdditional Example / Use-CasesNextDaily Reward

Was this helpful?

💻