Attempt to index nil with "PlayerGui"

What I am trying to do is to change the font of a text label on the player’s gui to something else. When running the game though, the error mentioned in the title shows up in the developer console.

plr = game.Players.LocalPlayer
plr.PlayerGui.MessageGui.Message.Font = Enum.Font.Code
wait(10)
plr.PlayerGui.MessageGui.Message.Font = Enum.Font.Gotham

have you made sure this is on a localscript? the error could be caused by that

Oh. Well then. I need a way to make the font change from a normal script. I have considered RemoteEvents, but I don’t know how I would exactly do that.

you do need a remote event in that case, it isn’t recommended to access playerguis from the server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.locationOfYourRemoteEvent

--when something happens:
remoteEvent:FireAllClients(Enum.Font.Code)
--//from local script (can be placed within the textlabel)
remoteEvent.OnClientEvent:Connect(function(font)
    Message.Font = font
end)

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