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

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

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?

1 comment

0

it's a normal script if your wondering

1 answer

✓ Accepted answer

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.

2 comments

1

Thank you SharkRayMaster!

0

np!

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