Hey so there were a few topics about this but some of them never had a concrete answer or weren’t all that related to this but would there be a way to give a bagde through Roblox’s default dialog system when selecting a specific option? (dialogchoice)
There is a way to do that you would just have to check which NPC the player is interacting with and when they make the choice you tied the badge to, fire a remote event or something, make sure to check on the server side that they did actually interact with that NPC, and do actually have the ability to make that choice, then reward the badge.
I dont know how badges work, I havent touched that aspect of studio yet, but I am sure that part would be easy-ish to find on the internet.
I tried with a remote event but it didn’t work or maybe I executed it wrong
The DialogChoiceSelected event will do this. The event is fired when the player chooses an option and will tell you what choice was picked. From there you just use the standard badge API.
I assume something like this would work.
Replace all of the placeholders and you should be good.
-- replace with your actual instances
local dialog = script.Parent:WaitForChild("Dialog")
local specificChoice = dialog:WaitForChild("DialogChoice")
specificChoice.DialogChoiceSelected:Connect(function(player)
-- check if the player has the badge or not
local hasBadge = game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, badgeId)
if not hasBadge then
-- replace badge id with the actual ID
game:GetService("BadgeService"):AwardBadge(player.UserId, 123456789)
end
end)
This code isn’t correct because the DialogueChoiceSelected event isn’t a member of DialogueChoice instances for some odd reason. You have to use the event on the Dialogue instance and use the dialogueChoice argument the event gives you in order to identify the correct DialogueChoice
It’s strange to do it this way but that’s how it works. Roblox should have just made DialogueChoice inherit from Dialogue but they made it inherit directly from Instance so the events arent available
Something like this should work, thanks for correcting
local dialog = script.Parent:WaitForChild("Dialog")
local specificChoice = dialog:WaitForChild("DialogChoice")
dialog.DialogChoiceSelected:Connect(function(player, dialogueChoice)
if dialogueChoice == specificChoice then
-- check if the player has the badge or not
local hasBadge = game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, badgeId)
if not hasBadge then
-- replace badge id with the actual ID
game:GetService("BadgeService"):AwardBadge(player.UserId, 123456789)
end
end
end)
So first of all the script doesnt work. Second in the line “local hasBadge = game:GetService(“BadgeService”):UserHasBadgeAsync(player.UserId, badgeId)” you forgot to add the variable of “badgeId” so it cant award any badges since it doesnt know the badge id. Third i dont think its a good idea to give a badge using dialogs since they are very weird to work with. I would suggest making or looking up for a custom dialog system instead of roblox old dialogs.