So this will be really dumb, since there’s a lot of official Roblox resources, but i can’t just get it… Basically i want to award a badge to inviter if the invited person joins the experience. I just don’t understand the whole context here and it seems really confusing to me…
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeService = game:GetService("BadgeService")
local referrerEvent = ReplicatedStorage:FindFirstChild("ReferralReceivedEvent")
local BADGE_ID = 0
function onPlayerAdded(player)
local joinData = player:GetJoinData()
local referredByPlayerId = joinData.ReferredByPlayerId
-- Check if the player was invited through a referral
if not referredByPlayerId or referredByPlayerId == 0 then
return
end
-- Fire the referral event to the client, passing the inviter's ID
referrerEvent:FireClient(player, referredByPlayerId)
-- Reward the inviter
local referrerPlayer = Players:GetPlayerByUserId(referredByPlayerId)
if referrerPlayer then
BadgeService:AwardBadge(referredByPlayerId, BADGE_ID)
end
end
-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)
Don’t forget to create :
A badge and put it’s asset id in the BADGE_ID variable
A RemoteEvent and put it inside the referrerEvent variable
(This script has to be in ServerScriptService)
Hmm. Maybe I’m doing something wrong… Should i put this script in replicated storage too?
function onPlayerAdded(player)
local referredByPlayerId = player:GetJoinData().ReferredByPlayerId
local referrerEvent: RemoteEvent = ReplicatedStorage:FindFirstChild("ReferralReceivedEvent")
referrerEvent:FireClient(player, referredByPlayerId)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Still nothing… This is weird… Is there a possibility that you could do a quick call with me? via. Discord or other platform. I want to show you how i set up the whole event etc…