PlayerGui not working

Hi there. I was working on my code Notiff (COMING SOON) and I got this error:

Here’s my code:
2

Any help is appreciated!

EDIT: It"s a ModuleScript

2 Likes

Try this

local icon = {}
local format = game:GetService('ReplicatedStorage'):WaitForChild('Format')
local themes = script.Parent.Parent:WaitForChild('Themes')

function icon:MakeNewNotiff()
    local player = game:GetService('Players').LocalPlayer
    local playerGui = player:WaitForChild('PlayerGui')
    local nf = format:Clone()
    wait(0.1)
    nf.Parent = playerGui
end
1 Like

I put it in, but then this happened:
image

2 Likes

I believe in order to use LocalPlayer it has to be in a Local Script

3 Likes

Yeah. Make it a local script or use remotes

2 Likes

It seems you are running client-side code (local code) on the server.

You need to put this code in a localscript and not in a normal script:

local NotiffModule = require(Workspace.Notiff.Scripts.Notiff)

NotiffModule:MakeNewNotiff()
2 Likes
local icons = {}
local format = game.ReplicateStorage.Format
script.Parent.Parent.Themes

function icon:MakeNewNotiff(player) 
    local nf = format:Clone()
    nf.Parent = player.PlayerGui
end

you can’t use the “LocalPlayer” variable in a server script or module script. Use this, and make sure when firing the function to put the “player” argument inside of the function, If you know what I mean :wink:

2 Likes

LocalPlayer is nil because it cannot be indexed by server scripts - you have to use remote events.

1 Like

Aight so

I used both of your scripts, but now it doesn’t have an error. Nor does the gui show.

My screen:
image

Code (localscript):
image

Path:
image

1 Like

make another variable. Name it to plr, and then put the player variable inside the function.

Like this:

local notiff = require(workspace.Notiff.Scripts.Notiff)
local plr = game.Players.LocalPlayer 

notiff:MakeNewNotiff(plr)

This should work since the localplayer is inside of the localscript.

1 Like

Any local script does not work in workspace. Instead put it on StarterPlayer>StarterPlayerScript

1 Like

That’s parenting to the player, not the player gui.

AYY it works! Tysm! 30charlimit