This is a normal script in a part in a model, within the workspace. I continue to get an error for line 5 of my current quest script and I'm not sure what's wrong. My goal is to have the UI fade in and out as of right now when the player interacts with the NPC, I tried my best to add a sort of annotation to the script.
**The error: **
Workspace.Torch.Button.Script:5: attempt to index nil with 'PlayerGui' - Server - Script:5
The script:
local button = script.Parent
local sound = button.man_farmer_encounter_1
local toggle = true --Toggles wether the player can do another quest.(One per in-game day)
local player = game:GetService("Players").LocalPlayer
player.PlayerGui.ChatGUI.NPCChat.Visible=false
function FadeOut() --Fade Out Chat
for i = 0.4, 1, .1 do
player.PlayerGui.ChatGUI.NPCChat.Conversation.TextTransparency = i
player.PlayerGui.ChatGUI.NPCChat.NPCName.TextTransparency = i
player.PlayerGui.ChatGUI.NPCChat.Agree.TextTransparency = i
player.PlayerGui.ChatGUI.NPCChat.Decline.TextTransparency = i
wait()
end
player.PlayerGui.ChatGUI.NPCChat:TweenSize(UDim2.new(0, 0,0, 130),"Out", "Quint" , 4)
end
function FadeIn() --Fade In Chat
player.PlayerGui.ChatGUI.NPCChat:TweenSize(UDim2.new(0, 0,0, 130),"Out", "Quint" , 4)
player.PlayerGui.ChatGUI.NPCChat.Visible=true
for i = 0, -0.6, .1 do
player.PlayerGui.ChatGUI.NPCChat.Conversation.TextTransparency = i
player.PlayerGui.ChatGUI.NPCChat.NPCName.TextTransparency = i
player.PlayerGui.ChatGUI.NPCChat.Agree.TextTransparency = i
player.PlayerGui.ChatGUI.NPCChat.Decline.TextTransparency = i
wait()
end
player.PlayerGui.ChatGUI.NPCChat:TweenSize(UDim2.new(0, 650,0, 130),"Out", "Quint" , 4)
end
button.ProximityPrompt.Triggered:Connect(function(player) -- When prompt is pressed
if toggle==true then -- Trigger quest selection
toggle = false
FadeIn()
repeat wait() until player.PlayerGui.ChatGUI.NPCChat.Size=="0, 650,0, 130"
local text = "I need help with me crops! Please help me lad, my back aches. Go clear half worths a plot and return the produce to me and i'll give ya some coin!"
for i = 1, #text do
player.PlayerGui.ChatGUI.NPCChat.Conversation.Text = string.sub (text, 1, i)
end
else
FadeIn()
repeat wait() until player.PlayerGui.ChatGUI.NPCChat.Size=="0, 650,0, 130"
local text = "I've already given you a job today, come back tomorrow for more."
for i = 1, #text do
player.PlayerGui.ChatGUI.NPCChat.Conversation.Text = string.sub (text, 1, i)
end
wait(5)
FadeOut()
end
end)
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if game.Lighting.ClockTime == 0 then
toggle = true --Re-enables the quest system when an in-game day passes
end
end)

4 comments
Ignore how the model is called torch lol
You cannot get the local player through a script. You will need to use remote events or use an event like .Touched
yes Soban06 is right
I appreciate everyone's help, been a while since I've made a script. Thanks guys!