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

why my script give local player (nil value)?

I'm trying to make an npc activate a script that is in game.players.LocalPlayer.PlayerGui.GuiName but the script give me the next error

Script:2: attempt to index field 'LocalPlayer' (a nil value)

script

script.Parent.NPCTalk.OnServerEvent:connect(function(player)
local plrGui = game.Players.LocalPlayer.PlayerGui
plrGui.Talk.Disabled = false
end) 

KeyBind Script

2 comments

0

You cannot access LocalPlayer from the server - you would instead use the provided player argument. Furthermore - you cannot access PlayerGui either afaik. Make UI changes on the client.

0

can you explain me how

1 answer

You cannot access LocalPlayer on a ServerScript, as you are not "Local". You should use your lovely player argument in your script. Also, you cannot access children of PlayerGui from the server. You should just access PlayerGui from the LocalScript in the first place. Here's what I would replace FireServer with in your LocalScript:

local plrGui = game.Players.LocalPlayer.PlayerGui
plrGui.Talk.Disabled = false

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