Attempt to Index Nil with PlayerGui

Basically I’m trying to make this module where it gives you a custom badge notification, not just a regular badge notification. For some reason, it just says “Attempt to Index Nil With PlayerGui”. Can someone help me out here?

local custom = {}
local gui = script:FindFirstChild("CustomBadgeNotificationUI")
local badgeservice = game:GetService("BadgeService")



function custom:CreateBadgeNotification(badgeid)
	
	local success, result = pcall(function()
		return badgeservice:GetBadgeInfoAsync(badgeid)
	end)
	
	if success then
		local cloneui = gui:Clone()
		cloneui.Parent = game.Players.LocalPlayer.PlayerGui
		local frame = cloneui:FindFirstChild("MainFrame")
		local image = frame:FindFirstChild("BadgeIcon")
		local title = frame:FindFirstChild("BadgeName")
		local description = frame:FindFirstChild("BadgeDescription")

		image.Image = "rbxassetid://"..result.IconImageId
		title.Text = "You won "..result.Name.."!"
		description.Text = result.Description
	end
end


return custom

1 Like

Maybe use LocalScript instead of Script?

but this is a modulescript, so im expecting that this should work

also another thing is this script keeps saying " SetCore: BadgesNotificationsActive has not been registered by the CoreScripts - Client - BadgeNotifDisable:1"

script: game:GetService(“StarterGui”):SetCore(“BadgesNotificationsActive” ,false)

That detail changes nothing, only executable context (etc client or server) does

--!strict
--!optimize 2
local gui = script.CustomBadgeNotificationUI
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local GetBadgeInfoAsync = BadgeService.GetBadgeInfoAsync
local Player = Players.LocalPlayer::Player
local PlayerGui = Player:WaitForChild("PlayerGui")::PlayerGui

return function(badgeid:number):()
	local success, result = pcall(GetBadgeInfoAsync,BadgeService,badgeid)
	if not success then return end

	local cloneui = gui:Clone()
	local frame = cloneui.MainFrame
	local image = frame.BadgeIcon
	local title = frame.BadgeName
	local description = frame.BadgeDescription

	image.Image = "rbxassetid://"..result.IconImageId
	title.Text = "You won "..result.Name.."!"
	description.Text = result.Description
	cloneui.Parent = PlayerGui
end
1 Like

Where are you calling the module script (i.e. using require on it)? Is that a normal script or a local script? Module scripts basically inherit if they are on the client or server from the script which calls them

im not using require on it. I made the module my self.

By using a remotevent, your still able to get the same thing. so i just used a remotevent anyways.

??

The code within module scripts only runs if it gets required (require()).
Require can take a path rather than a number (e.g. require(script.Parent.MODULE))

1 Like

i just started coding so i kinda dont know what ur saying tbh i was trying to use a modulescript for simpler ways, but using a remoteevent is the same thing, if i would have to use the function in the module, i would have to do function(player, badgeid) not function(badgeid)

Ok sorry for the confusion about this. It seems like using a serverscript which I used won’t work with it I’m pretty sure.

Yeah - the module script was running from the server, so there would be no LocalPlayer for you to access, causing the issue.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.