Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Clicks are not detected by script, code doesn't prop any errors?

local badgeservice = game:GetService("BadgeService")
local id = 2128449719
local part = script.Parent
local detector = part.ClickDetector

detector.MouseClick:Connect(function(player)
	print("clicked")
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	badgeservice:AwardBadge(plr.UserId, id)
end)

im attempting to give a player a badge when clicking an object. However when testing in Roblox Studio's test area, nothing occurs. I have added a ClickDetector as a child to said object as well, i haven't forgotten.

4 comments

0

Do you already own the badge? Did you try it in a live server?

0

no i tried to get it with a different account but it still didnt work

0

Did you make sure to publish the game?

0

yes i published it and enyone can join

1 answer

I see a problem. You have the parameters of the connection as 'player', yet you try to use 'hit.Parent', even though it is never defined. Clickdetector.MouseClick returns the player who clicked as params, so you don't need getplayerfromchar, just remove the line (08) and it should work

remember to change badgservice params to player.userid, id

2 comments

0

i prefer if you could say it clearer

0

How much clearer do you need it to be? You never defined hit, so you can't use it. Simple.

This discussion is preserved as it was. New answers, comments, and votes are closed.