Trouble making an OnClick item

I’m having trouble with this script I am making, I am making a quest where if you click an item it will give you rewards, but it doesn’t work. The error is on the if statement but I can’t see why that’s an error because there are no errors in output. It is a script inside the part. It prints “clicked” and not “Value is true” even though the value is true when I checked.

local ClickDetector = script.Parent.ClickDetector
local NotesEvent = game.ReplicatedStorage.Notes
local QuestGUI = game.ReplicatedStorage.NotesQuestFinishedGui
function onClick(click)
	print("clicked")
	local PaperQuest = click.PaperQuest
	if PaperQuest.Value == true then
	print("Value is true")
	NotesEvent:Fire()
	QuestGUIClone = QuestGUI:Clone()
	QuestGUIClone.Parent = click.PlayerGui
	click.leaderstats.Coins.Value = click.leaderstats.Coins.Value + 5
	click.leaderstats.XP.Value = click.leaderstats.XP.Value + 100
	script.Parent:Destroy()
	end
end
ClickDetector.MouseClick:Connect(onClick)
1 Like

Well click is a Player Instance, are you sure that there is something in Player?

PaperQuest is in Player and its value must be true.

1 Like

Try switching your Studio test build to Server instead of Client and verify that the PaperQuest.Value is still true. If you are setting a value to true on the client then it will still read false on the Server, therefore generating this problem.

2 Likes


Yeah, I took a picture and the PaperQuest is there

Try this

local ClickDetector = script.Parent:WaitForChild("ClickDetector")
local NotesEvent = game.ReplicatedStorage:WaitForChild("Notes")
local QuestGUI = game.ReplicatedStorage:WaitForChild("NotesQuestFinishedGui")

function onClick(click)
	print("clicked")
	local PaperQuest = click:FindFirstChild("PaperQuest")
	if PaperQuest.Value == true then
		print("Value is true")
		NotesEvent:Fire()
		local QuestGUIClone = QuestGUI:Clone()
		QuestGUIClone.Parent = click:FindFirstChild("PlayerGui")
		click.leaderstats.Coins.Value += 5
		click.leaderstats.XP.Value += 100
		script.Parent:Destroy()
	end
end

ClickDetector.MouseClick:Connect(onClick)
2 Likes

It prints ‘clicked’ and doesn’t do anything else

1 Like

Was there any errors in the output?

4 Likes

no errors at all (30 characters)

1 Like

That then means it’s not passing this.

if PaperQuest.Value == true then

There is logic problem then. Try printing the value before the if-statement.

1 Like

is PaperQuest boolvalue created on the server? If not then that will be the Issue.

1 Like

the paperquest is created on the server

game.Players.PlayerAdded:Connect(function(player)
	local PaperQuest = Instance.new("BoolValue", player)
	PaperQuest.Name = "PaperQuest"
	PaperQuest.Value = false
end)

It prints false, but when I checked it, it was true
image

Not sure what is causing the Issue exactly however this might work.

local ClickDetector = script.Parent:WaitForChild("ClickDetector")
local NotesEvent = game.ReplicatedStorage:WaitForChild("Notes")
local QuestGUI = game.ReplicatedStorage:WaitForChild("NotesQuestFinishedGui")

local Enabled = true

ClickDetector.MouseClick:Connect(function(Player)
	print("clicked")
	local PaperQuest = Player:FindFirstChild("PaperQuest")
	if PaperQuest and PaperQuest.Value == true and Enabled == true then
		print("Value is true")
		Enabled = false
		NotesEvent:Fire()
		local QuestGUIClone = QuestGUI:Clone()
		QuestGUIClone.Parent = Player:FindFirstChild("PlayerGui")
		Player.leaderstats.Coins.Value += 5
		Player.leaderstats.XP.Value += 100
		delay(1, function()
			script.Parent:Destroy()
		end)
	elseif not PaperQuest then
		print("PaperQuest is not a valid member of", Player.Name)
	else
		print(PaperQuest.Value)
	end	
end)
1 Like

When I did that it prints
“Clicked” and “False”

That means the PaperQuest.Value is False, Seems like you are setting the PaperQuest Value on the Client.

1 Like

Oh yeah, I made a gui for that and it was on the client

local Button = script.Parent
local Player = game:GetService("Players").LocalPlayer
function buttonClicked()
	Button.Parent.Parent.Enabled= false
	Player.PaperQuest.Value = true
end
Button.MouseButton1Click:Connect(buttonClicked)

I will change that to

local Button = script.Parent
function buttonClicked(click)
	Button.Parent.Parent.Enabled= false
	click.PaperQuest.Value= true
end
Button.MouseButton1Click:Connect(buttonClicked)

EDIT:
Turns out that doesn’t work as I get the error 20:37:11.762 - Players.SadWowow21.PlayerGui.NotesQuestGui.Frame.AcceptButton.Script:4: attempt to index nil with ‘PaperQuest’

You are changing its value on the Client! You need to fire RemoteEvent to change it on the Server!

1 Like