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

Quest System UI not identifying the local player?

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

0

Ignore how the model is called torch lol

0

You cannot get the local player through a script. You will need to use remote events or use an event like .Touched

0

yes Soban06 is right

0

I appreciate everyone's help, been a while since I've made a script. Thanks guys!

1 answer

✓ Accepted answer

This is a normal script in a part in a model

You CANNOT get the LocalPlayer on the server, only in localscripts.

Your option could be to use RemoteEvent, an instance for single communications between the client to server / server to client / server to all clients. From your server script in the model, you could do:

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)


button.ProximityPrompt.Triggered:Connect(function(player) -- When prompt is pressed
	if toggle==true then -- Trigger quest selection
		toggle = false
		game:GetService("ReplicatedStorage").RemoteEvent:FireClient(player, "Quest") --.FireClient requires a player instance to fire event to.
	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)

And then handle your GUI stuff in a localscript on the clientside.

1 comment

0

And why is it that the LocaPlayer pointer returns nil?

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