Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
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.

0
Do you already own the badge? Did you try it in a live server? OhManXDXD 445 — 2y
0
no i tried to get it with a different account but it still didnt work Kriner2 0 — 2y
0
Did you make sure to publish the game? HeroFigo 81 — 2y
0
yes i published it and enyone can join Kriner2 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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

0
i prefer if you could say it clearer Kriner2 0 — 2y
0
How much clearer do you need it to be? You never defined hit, so you can't use it. Simple. Kingu_Criminal 205 — 2y
Ad

Answer this question