I have a quest gui that shows the quest’s objective. However, when the objective is changed (from another script) and the quest menu is pulled up again, the objective doesn’t change in the gui, this is because the script dictates that the quest button should be pressed before the objective changes.
I know that this code is flawed, but I don’t have a clue on how I should fix it.
tldr: If the quest gui for the specific quest is selected, the objective should change without having to be clicked again.
Here’s a picture of the quest gui:
Thanks to anyone willing to help! Here’s the code aswell:
Note: the script that makes the quest gui (such as the ‘Lumberjacking’ quest) visible is handled in another script. You can find the script under “–second script”
local frame = script.Parent
local clicked = false
local player = game.Players.LocalPlayer
frame.Lumberjacking.MouseButton1Down:Connect(function()
local questName = game.ReplicatedStorage.QuestsReplicated:FindFirstChild("Lumberjacking").Name
if player.Quests:FindFirstChild(questName) then
if clicked == false then
clicked = true
repeat
local quest = player.Quests:FindFirstChild(questName)
frame.Parent.QuestInformation.QuestTitle.Text = quest.Name
frame.Parent.QuestInformation.RecommendedLevel.Text = "Recommended LVL: " .. quest.RecommendedLevel.Value
frame.Parent.QuestInformation.QuestDescription.Text = quest.Description.Value
frame.Parent.QuestInformation.QuestReward.Text = "Reward: " .. quest.ExpReward.Value .. " EXP, " .. quest.MoneyReward.Value .. " COINS"
frame.Parent.QuestInformation.QuestObjective.Text = quest.Objective.Value
until clicked == true
if clicked == true then
clicked = false
end
end
end
end)
-------------
frame.Doppelsoldner.MouseButton1Down:Connect(function()
local questName = game.ReplicatedStorage.QuestsReplicated:FindFirstChild("Doppelsoldner").Name
if player.Quests:FindFirstChild(questName) then
if clicked == false then
clicked = true
repeat
local quest = player.Quests:FindFirstChild(questName)
frame.Parent.QuestInformation.QuestTitle.Text = quest.Name
frame.Parent.QuestInformation.RecommendedLevel.Text = "Recommended LVL: " .. quest.RecommendedLevel.Value
frame.Parent.QuestInformation.QuestDescription.Text = quest.Description.Value
frame.Parent.QuestInformation.QuestReward.Text = "Reward: " .. quest.ExpReward.Value .. " EXP, " .. quest.MoneyReward.Value .. " COINS"
frame.Parent.QuestInformation.QuestObjective.Text = quest.Objective.Value
until clicked == true
if clicked == true then
clicked = false
end
end
end
end)```
```lua
-- second script
wait(1)
while wait(0.1) do
if game.Players.LocalPlayer.Quests:FindFirstChild(script.Parent.Name) then
script.Parent.Text = script.Parent.Name
if game.Players.LocalPlayer.Quests:FindFirstChild(script.Parent.Name).Value == true then
script.Parent.BackgroundColor3 = Color3.fromRGB(0,161,0)
end
end
end```
Thanks for offering a possible solution. However, I tried it and it doesn’t really solve the issue - I basically need to have the text change constantly without pressing the button. If I’m being unclear feel free to ask for a more detailed explanation - it’s quite a difficult and vague problem to tackle.
Create a table of the list of quests then put a while loop and a wait function inside the loop. Then put an if not statement. The if not statement will basically check if the text is correct like the text in the table for that certain quest. If the if not returns true, it changes the text.
local questinfo = {
["Quest1"] = {
["Text"] = "Put Text Here",
["Rewards"] = {Gold = 50; Gems = 50}
};
}
while true do
wait(3) -- how long to wait
local currentquest = script.Parent.CurrentQuest
local quest = questinfo[currentquest.Value]
if script.Parent.Text == not quest["Text"] then
script.Parent.Text = quest["Text"]
end
end
You could add this for the rewards and so on with the info of the quest. This is just a example off the top of my head.
Thanks again for your feedback. But how would this work if I tried to change the quest tab (from Lumberjacking to Doppelsoldner, for example)? Wouldn’t the while loop keep playing if I tried to do so?
Good news, everyone! With some inspiration from @MegaFireball0 I’ve managed to add in a while loop that fixes the script. I’ll leave it here, thanks for the help!
local clicked = false
local player = game.Players.LocalPlayer
frame.Lumberjacking.MouseButton1Down:Connect(function()
local questName = game.ReplicatedStorage.QuestsReplicated:FindFirstChild("Lumberjacking").Name
if player.Quests:FindFirstChild(questName) then
if clicked == false then
clicked = true
while true do
wait(0.1)
local quest = player.Quests:FindFirstChild(questName)
frame.Parent.QuestInformation.QuestTitle.Text = quest.Name
frame.Parent.QuestInformation.RecommendedLevel.Text = "Recommended LVL: " .. quest.RecommendedLevel.Value
frame.Parent.QuestInformation.QuestDescription.Text = quest.Description.Value
frame.Parent.QuestInformation.QuestReward.Text = "Reward: " .. quest.ExpReward.Value .. " EXP, " .. quest.MoneyReward.Value .. " COINS"
frame.Parent.QuestInformation.QuestObjective.Text = quest.Objective.Value
if clicked == true then
clicked = false
break
end
end
end
end
end)
frame.Doppelsoldner.MouseButton1Down:Connect(function()
local questName = game.ReplicatedStorage.QuestsReplicated:FindFirstChild("Doppelsoldner").Name
if player.Quests:FindFirstChild(questName) then
if clicked == false then
clicked = true
while true do
wait(0.1)
local quest = player.Quests:FindFirstChild(questName)
frame.Parent.QuestInformation.QuestTitle.Text = quest.Name
frame.Parent.QuestInformation.RecommendedLevel.Text = "Recommended LVL: " .. quest.RecommendedLevel.Value
frame.Parent.QuestInformation.QuestDescription.Text = quest.Description.Value
frame.Parent.QuestInformation.QuestReward.Text = "Reward: " .. quest.ExpReward.Value .. " EXP, " .. quest.MoneyReward.Value .. " COINS"
frame.Parent.QuestInformation.QuestObjective.Text = quest.Objective.Value
if clicked == true then
clicked = false
break
end
end
end
end
end)
-------------