-
I want to be able to update my quest value without relying on fireclient so that whenever the player completes the quest the have to go back to the npc to trigger the completion dialogue instead of the dialogue popping up once the player completes the quest.
-
I am sure that the main problem is that since the value is on a local script and when I change it on a server script it will not work.
Heres my scripts:
Local script
local rs = game:GetService("ReplicatedStorage")
local stg = game:GetService("StarterGui")
local plr = game.Players.LocalPlayer
rs.RemoteEvents.quest1.OnClientEvent:Connect(function(state, newquest)
print("Fired")
local maxcount = 3
local uihandler = require(rs:FindFirstChild("modules").UIColorhandler)
local dialogoptions = require(rs:FindFirstChild("modules").QuestData)
local questhandler = require(rs:FindFirstChild("modules").QuestHandler)
print(questhandler.savedvalues[plr.UserId])
local quest2 = rs:FindFirstChild("Quests")["Quest#2"]:Clone()
print(quest2.Value)
local textFrame = plr.PlayerGui.QuestGui:FindFirstChild("Quest#1"):FindFirstChild("DialogFrame")
local UI = {
questframe2 = plr.PlayerGui.QuestGui:FindFirstChild("Quest#2").QuestFrame,
dialogtxtbutton = textFrame.Dialog,
txtlabel = textFrame.TextLabel,
no = textFrame.Nah,
yes = textFrame.Yes
}
print(UI.no)
quest2.Changed:Connect(function()
print('Changed')
end)
local color1 = Color3.fromRGB(67, 123, 255)
local color2 = Color3.fromRGB(45, 83, 172)
print(dialogoptions["Quest#2"])
print(quest2.Value)
if state == "NewValue" then
print("EVERYONES IS A BAD GUYYY")
uihandler.UiHandler(plr, textFrame, color1, color2)
questhandler.QuestHandler(plr,newquest, UI.no, UI.yes, UI.dialogtxtbutton, dialogoptions["Quest#2"].Kate, dialogoptions["Quest#2"].player, maxcount)
return
end
if stg.QuestGui.Enabled then
uihandler.UiHandler(plr, textFrame, color1, color2)
questhandler.QuestHandler(plr,quest2, UI.no, UI.yes, UI.dialogtxtbutton, dialogoptions["Quest#2"].Kate, dialogoptions["Quest#2"].player, maxcount)
else
print("didnt work")
end
end)
--[[rs.RemoteEvents.questfinish.OnClientEvent:Connect(function(state, newquest)
local maxcount = 3
local uihandler = require(rs:FindFirstChild("modules").UIColorhandler)
local dialogoptions = require(rs:FindFirstChild("modules").QuestData)
local questhandler = require(rs:FindFirstChild("modules").QuestHandler)
local quest2 = rs:FindFirstChild("Quests")["Quest#2"]:Clone()
local textFrame = plr.PlayerGui.QuestGui:FindFirstChild("Quest#1"):FindFirstChild("DialogFrame")
local UI = {
questframe2 = plr.PlayerGui.QuestGui:FindFirstChild("Quest#2").QuestFrame,
dialogtxtbutton = textFrame.Dialog,
txtlabel = textFrame.TextLabel,
no = textFrame.Nah,
yes = textFrame.Yes
}
print(plr, state, newquest)
local color1 = Color3.fromRGB(67, 123, 255)
local color2 = Color3.fromRGB(45, 83, 172)
if state == "NewValue" then
uihandler.UiHandler(plr, textFrame, color1, color2)
questhandler.QuestHandler(plr,newquest, UI.no, UI.yes, UI.dialogtxtbutton, dialogoptions["Quest#2"].Kate, dialogoptions["Quest#2"].player, maxcount)
end
end)--]]
QuestHandleModule
local module = {}
local rs = game:GetService("ReplicatedStorage")
module.savedvalues = {}
module.QuestHandler = function(plr,quest, branch1, branch2, questframe, npcdialogueoptions, playerdialogueoptions, maxcount)
local questdata = require(script.Parent.QuestData)
local slow = 0.1
local state = module.savedvalues[plr.UserId] or false
module.savedvalues[plr.UserId] = state
print(module.savedvalues[plr.UserId])
questframe.MouseButton1Click:Connect(function()
slow = 0
if questframe.Text == npcdialogueoptions.Unfinished or questframe.Text == npcdialogueoptions.Completed then
questframe.Parent.Visible = false
end
end)
local function disableButtons()
branch1.Visible = false
branch2.Visible = false
end
local function typewrite(obj, text)
obj.Text = ""
for i = 1, #text do
task.wait(slow)
obj.Text = string.sub(text, 1, i)
end
end
local function wipe()
for i, v in pairs(questframe.Parent:GetChildren()) do
if v:IsA("TextButton") then
v.Text = ""
slow = 0.1
end
end
end
print(quest.Value)
quest.Changed:Connect(function()
print('dah daha ahaha')
end)
print(quest.Count.Value)
if state and not quest.Value then
print('UNFINISHED')
print(quest.Value)
disableButtons()
typewrite(questframe, npcdialogueoptions.Unfinished)
return
elseif quest.Value and state then
print("DONE!")
disableButtons()
typewrite(questframe, npcdialogueoptions.Completed)
return
end
typewrite(questframe, npcdialogueoptions.text.Question)
branch1.MouseButton1Click:Once(function()
questframe.Parent.Visible = false
end)
branch2.MouseButton1Click:Once(function()
wipe()
typewrite(questframe, npcdialogueoptions.text.Mission)
if npcdialogueoptions.text.Mission then
typewrite(branch1, playerdialogueoptions.Decline[2])
typewrite(branch2, playerdialogueoptions.Accept)
if branch2.Text == playerdialogueoptions.Accept then
branch2.MouseButton1Click:Once(function()
questframe.Parent.Visible = false
state = true
module.savedvalues[plr.UserId] = state
rs.RemoteEvents.quest1:FireServer("QuestActivated", state)
end)
end
end
end)
if npcdialogueoptions.text.Question then
typewrite(branch1, playerdialogueoptions.Decline[1])
typewrite(branch2, playerdialogueoptions.Next)
end
print(module.savedvalues[plr.UserId])
end
return module
server script
local rs = game:GetService("ReplicatedStorage")
local questremote = rs:FindFirstChild("RemoteEvents").quest1
local stg = game:GetService("StarterGui")
script.Parent.Triggered:Connect(function(plr)
questremote:FireClient(plr)
rs.RemoteEvents.quest1.OnServerEvent:Connect(function(plr, state, boolean)
if state == "QuestActivated" then
print("HAJIME STARTOOOO")
local mxcount = 3
local accept = require(rs:FindFirstChild("modules").QuestAccept)
local quest2 = rs:FindFirstChild("Quests")["Quest#2"]:Clone()
local textFrame = plr.PlayerGui.QuestGui:FindFirstChild("Quest#1"):FindFirstChild("DialogFrame")
local UI = {
questframe2 = plr.PlayerGui.QuestGui:FindFirstChild("Quest#2").QuestFrame,
dialogtxtbutton = textFrame.Dialog,
txtlabel = textFrame.TextLabel,
no = textFrame.Nah,
yes = textFrame.Yes
}
print(boolean)
quest2.Parent = plr
accept.Accept(plr, UI.questframe2, textFrame, quest2, mxcount, boolean)
print(quest2.Parent)
elseif state == "NewValue" then
print("NEWWWWW")
end
end)
end)
quest accept module
local module = {}
local rs = game:GetService("ReplicatedStorage")
module.Accept = function(plr,objectiveframe, questframe, quest, maxcount, state)
local savedvalues = require(script.Parent.QuestHandler)
local fired = rs.RemoteEvents.quest1
print("YOSHAAA")
objectiveframe.Visible = true
print(savedvalues.savedvalues)
quest.Count:GetPropertyChangedSignal("Value"):Connect(function()
local newcount = quest.Count.Value
objectiveframe.Objective.Text = "• Kill 3 zombies: "..newcount.."/"..3
if quest.Count.Value == maxcount then
objectiveframe.Visible = false
quest.Value = true
state = false
savedvalues.savedvalues = state
fired:FireClient(plr,"NewValue", quest)
end
end)
end
return module