Hello! I’m actually creating a very basic game in which the objective is to find the right button inside a big room with buttons to receive a badge. I’m completely new scripting and everything that is out of building in Roblox Studio. The buttons only contain a ClickDetector and a couple of scripts that are responsible for changing the color of the button when you press it and another that allows you to hear a sound every time you click it. What can I do to receive a badge when I click on the correct button? I need a good explanation to understand and learn… Thank you very much!
Just a side note: no need to sign your post. Your username is already on your posts!
You use the BadgeService:AwardBadge to award badges. You can look on the api reference page for badgeservice for other methods that might be useful to you.
You could either use a ClickDetector or you could have a script that uses the Part.Touched() event. You would also have to find the player who touched / clicked it
Here is an example:
Click button
BadgeService = game:GetService("BadgeService")
PlayerService = game:GetService("Players")
Button = workspace.Button
ClickDetector = Button.ClickDetector
BadgeId = 123 -- the ID of your badge
Button.ClickDetector.MouseClick:Connect(function(Player)
BadgeService:AwardBadge(Player.UserId, BadgeId)
end)
Touch Button
BadgeService = game:GetService("BadgeService")
PlayerService = game:GetService("Players")
Button = workspace.Button
BadgeId = 123 -- the ID of your badge
Button.Touched:Connect(function(hit)
if hit.Parent then
local Player = PlayerService:FindFirstChild(hit.Parent.Name) -- checks if it was a player that touched it
if Player then
BadgeService:AwardBadge(Player.UserId, BadgeId)
end
end
end)
Yes but what if an NPC touches it? the script will just return with an error, cause the NPC isn’t a player. Unless you add in a check function or something
That’s probably because you have to change the parameter from hit.Parent.Name to hit.Parent since the parameter for GetPlayerFromCharacter is an instance and not a string.