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
We start by requiring the necessary modules from the GiftoinModule.
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).
The
onPlayerJoin
function is defined to send points to a player when they join. It usesGiftoinApi.sendPoint()
with the following parameters:robloxId
: The player's Roblox User ID as a stringcampaignId
: The ID of your campaignpointId
: The ID of the point type you're awardingquantity
: The number of points to award
We connect the
onPlayerJoin
function to thePlayerAdded
event, so it runs whenever a new player joins the game.We also set up an event handler for the
ClaimGiftoinEvent
. This demonstrates how to use thesendPoint
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'sUserId
and converted to a string, as required by thesendPoint
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.
Was this helpful?