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

can anyone help me with attempt to index nil with 'UserHasBadgeAsync' please?

Asked by
VipDanT 10
2 years ago

Here's the error:

Players.VipDanT.PlayerGui.Game.Badges.MainBadges.Script:4: attempt to index nil with 'UserHasBadgeAsync'

Here's the code:

local player = game.Players.LocalPlayer
local gmt = script.Parent["Game Monster"]

if player:UserHasBadgeAsync(function(text)
        gmt.Text = "Joshua - He doesn't like visitors staying too long"
    end) then
end

I'm trying to make it so that if you own the badge, the text changes to gmt.text, however it is not working. anyone know why?

0
it's a normal script if your wondering VipDanT 10 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Um... I'm not sure what you wrote there but, the function player:UserHasBadgeAsync requires 2 parameters, the player's UserId, and the BadgeId

So you could do something like this:

local player = game.Players.LocalPlayer

local gmt = script.Parent["Game Monster"]

local BadgeS = game:GetService("BadgeService")
local BadgeID = 2124475816

if BadgeS:UserHasBadgeAsync(player.UserId, BadgeID) then
    gmt.Text = "Joshua - He doesn't like visitors staying too long"
end

This script will only work on a LocalScript btw, I know you said it was a normal script, yet you used LocalPlayer, which only works on LocalScripts lol

Of course that also means the edited text will not replicate in the server, and only change for the client.

1
Thank you SharkRayMaster! VipDanT 10 — 2y
0
np! SharkRayMaster 265 — 2y
Ad

Answer this question