Get Which Player Activated Dialog

Hey there!

So, I’ve made a script that detects when the dialog gets activated but I’m not sure how to get the player who activated it, does anyone know how to help me? Thanks.

local badgeService = game:GetService("BadgeService")
local id = 2125440653

script.Parent:GetPropertyChangedSignal('InUse'):Connect(function()
	if not script.Parent.InUse then return end
	badgeService:AwardBadge(plr.UserId, id) -- Need player for here
end)
2 Likes
local badges = game:GetService("BadgeService")
local userHasBadgeAsync = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 0 --Change to ID of badge.

local dialog = script.Parent
dialog:GetPropertyChangedSignal("InUse"):Connect(function()
	for _, player in ipairs(dialog:GetCurrentPlayers()) do
		local success, result = pcall(userHasBadgeAsync, badges, player.UserId, badgeId)
		if success then
			if not result then
				local success, result = pcall(awardBadge, badges, player.UserId, badgeId)
				if success then
					if result then
						print("Badge awarded!")
					end
				else
					warn(result)
				end
			end
		else
			warn(result)
		end
	end
end)
2 Likes

Doesn’t that award every player the badge when just 1 person clicks on it?

1 Like
for _, player in ipairs(dialog:GetCurrentPlayers()) do

This gets an array of players currently interacting with the dialog.

2 Likes