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)
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.
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)
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)
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)