Ad
Log in to vote
0

How to tell which player clicked a button? [closed]

Asked by
zomspi 546 Moderation Voter
1 year ago

I am doing stuff with awarding badges and was wondering how to award a badge to the person who clicked a text button? I am thinking of using a script because I'm pretty sure that's what you use with badges. Is there any way I can do this without using remote events or do I have to use them?

0
Do you have a script? WideSteal321 770 — 1y

Closed as Not Constructive by hiimgoodpack, ForeverBrown, EmbeddedHorror, and BlackOrange3343

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
Xapelize 1080 Moderation Voter
1 year ago
Edited 1 year ago

You can use it, or don't use it. There's no way to say do you need to use it. If you use it correctly, the script also works.

I think you should don't need to use RemoteEvent. RemoveEvent is a thing that's let the server's player knows, that called: FireServer().

You must put this script into the StarterGui > Button. Also, you must do it a script. Not a LocalScript or ModuleScript.

Let get right into the script.

local BadgeID = (000000000)

This is your Badge ID. It can be founded in 'View > Show > Game Explorer'. You must public the game to found your badge inside the 'Game Explorer > Badges'. Right-click on the badge and select 'Copy ID to clipboard'.

local BadgeService = game:GetService("BadgeService")

BadgeService is a 'service' that gives you to award badge to the people, but this wasn't work in Roblox Studio, that's why I tell you public the game.

local button = game.StarterGui.Button

Important, you must change the 'Button' to your button's name.

function onClicked(player)
    if not BadgeService:UserHasBadgeAsync(player.UserId, badgeID) then
       BadgeService:AwardBadge(player.UserId, badgeID)

The first line, script creates a function that on clicked. Second, If the player doesn't get the badge yet... Third, the BadgeService will award the badge to you.

Last line:

button.Mouse1Down:Connect(onClicked)

Finally, this line tells us when the player 'MouseButton1Click', simply called clicked, then connects with the function 'onClicked'. Is this like connecting Redstone? xD

Ok, the entire script :

local badgeID = (000000000)
local badgeService = game:GetService("BadgeService")
local button  = game.StarterGui.Button

function onClicked(player)
    if not badgeService:UserHasBadgeAsync(player.UserId, badgeID) then
        badgeService:AwardBadge(player.UserId, badgeID)
    end
end

button.MouseButton1Click:Connect(onClicked)

Hope I helped, if you have any questions, comment below! :D

Thanks for reading, have a nice day and bye!

0
My grammar is so bad xD    Rip my all English teacher 2019-2019 Xapelize 1080 — 1y
0
I like how you cut the script in the parts, but one part you forgot the ends.. lol XviperIink 428 — 1y
0
This helps a lot, but is it possible to make it invisible (with a script) after you click it? zomspi 546 — 1y
0
Yep. I dare you to try yourself with MouseButton1Down and Visible >:) If you don't know how to do, tell me so i'll tell you tha answer >:) Xapelize 1080 — 1y
View all comments (12 more)
0
Good lack :) Xapelize 1080 — 1y
0
so would I have to do something like, player.StarterGui.ScreenGui.Frame.TextButton.Visible = true, I'm a bit confused about how I will do it only locally. zomspi 546 — 1y
0
Oh, you can do Player:WaitForChild("PlayerGui").ScreenGui.Frame.TextButton.Visible.. Maybe try to do this..? Xapelize 1080 — 1y
0
cool, I will! zomspi 546 — 1y
0
The visibility thing worked but it isn't awarding me my badge? I deleted it from my inventory but it still didn't work? Thanks so much though for helping me, I have been searching for weeks! zomspi 546 — 1y
0
Oh wait,wait. I put this script into the ServerScriptService :V I forget to tell u Xapelize 1080 — 1y
0
Yea, I did that zomspi 546 — 1y
0
nvm, the visibility thing doesn't work either, this is the error zomspi 546 — 1y
0
BadgeId '2124489619' is not of type Badge. Please use MarketplaceService:PlayerOwnsAsset instead. zomspi 546 — 1y
0
also is it possible to do badge stuff in a local script? zomspi 546 — 1y
0
MarketplaceService:PlayerOwnsAsset was a type of function that give peoples buy Gamepasses. Xapelize 1080 — 1y
0
No. LocalScript is impossible to do award badge, if you figured out the way to use LocalScript and award badge to other then teach me :V Xapelize 1080 — 1y
Ad
Log in to vote
0
Answered by
zomspi 546 Moderation Voter
1 year ago

k, I kinda answered some of my questions: 1. No it isn't possible in a local script 2. The badge script I think works, the thing that doesn't work is the button press, there is a problem with it to do with the script working with a client side thing.

Script I got from a channel to test if the badge works (it does)

game.Players.PlayerAdded:Connect(function(plr)
 if plr then
  game:GetService("BadgeService"):AwardBadge(plr.userId, 2124489619)
 end
end)

My current badge button script (I changed the "if not" to see if it worked because I have had previous encounters where "not" has not worked but it didn't change anything.

local badgeID = 2124489619
local badgeService = game:GetService("BadgeService")
local button  = game.StarterGui.Frame4.Noob

button.MouseButton1Click:Connect(function(player)
    if badgeService:UserHasBadge(player.UserId, badgeID) then

else
        badgeService:AwardBadge(player.UserId, badgeID)
end
end)





0
Its same. First script is the people joined then give the player badge. Second is make the local BadgeId's brackets remove. Its same, keep going! Great job dude :D Xapelize 1080 — 1y
0
For some reason though the second script doesn't give the badge? zomspi 546 — 1y