Quest System not giving me the reward or showing i completed the quest

I’m trying to make a random quest because im making a quest system, if this works I would’ve been done with the gui. I need help fixing the problem when you walk 500 studs, out of 500, it just goes over 500 and doesn’t show i completed the quest.

Dialouge Local Script:

print("hey guyssyfuihewfiuhewfiuwf")
local explorer = workspace["QUEST NPCS"].Part
local player = game.Players.LocalPlayer
local beforegui = player.PlayerGui:WaitForChild("QuestDialouge")
local gui = beforegui:WaitForChild("QuestDialogue")

print("beforegui looolll")
local db = false
print("Hey guys whats up today so im going to say hello")
explorer.Touched:Connect(function()
	print("1")
	if not db then
		db = true
		print("2")
		beforegui.Enabled = true
		print("3")
	gui.NPCName.Text = "Part"
	local chatText = "Hey! I need you to explore this island for me, I need approximately 500 studs explored before I can uncover the mystery of this island, I hear theres a strange thing below here! Will you help me?"
	for i = 1, string.len(chatText) do
		wait(0.025)
		gui.Dialogue.Text = string.sub(chatText, 1, i)
			script.Parent.Parent.Sound:Play()
		end
		gui.Option1.Text = "Sure!"
		gui.Option2.Text = "Nope, I don't want to."
		gui.Option1.Visible = true
		gui.Option2.Visible = true
		print("4")
		db = false
	end
end)

gui.Option1.MouseButton1Click:Connect(function()
	gui.Option1.Visible = false
	gui.Option2.Visible = false
	local chatText = "Thanks man!"
	for i = 1, string.len(chatText) do
		wait(0.025)
		gui.Dialogue.Text = string.sub(chatText, 1, i)
		script.Parent.Parent.Sound:Play()
	end
    wait(2)
	beforegui.Enabled = false
	game.ReplicatedStorage.QuestRemotes.Walk500Studs.GiveQuest:FireServer()
	wait(2)
	script.Parent.GiveQuest.Enabled = true
end)

gui.Option2.MouseButton1Click:Connect(function()
	gui.Option1.Visible = false
	gui.Option2.Visible = false
	local chatText = "You don't want to? Well.. If you change your mind come to me, I'm waiting for you here."
	for i = 1, string.len(chatText) do
		wait(0.025)
		gui.Dialogue.Text = string.sub(chatText, 1, i)
		script.Parent.Parent.Sound:Play()
	end
	wait(2)
	beforegui.Enabled = false
	game.ReplicatedStorage.QuestRemotes.Walk500Studs.GiveQuest:FireServer()
	wait(1)
	
end)

local eb = false

explorer.Touched:Connect(function()
	if player:WaitForChild("Quest"):WaitForChild("CurrentQuest"):WaitForChild("PathFinder"):WaitForChild("QuestDone").Value == true then
		if not eb  then
			eb = true
			local chatText = "Whoa! Thats a bunch of information! Thank you"..player.Name.."If thats your name. Goodbye!"
			for i = 1, string.len(chatText) do
				wait(0.025)
				gui.Dialogue.Text = string.sub(chatText, 1, i)
				script.Parent.Parent.Sound:Play()
				game.ReplicatedStorage.QuestRemotes.Walk500Studs.GivePrize:FireServer()
  			end
		end
	end
end)

Workspace Script tracking how much I walked studs

--//Services
local Players = game:GetService("Players")

--//Functions
Players.PlayerAdded:Connect(function(player)
	local totalDistance = 0
	local previousPosition = nil

	player.CharacterAdded:Connect(function(character)
		task.defer(function()
			previousPosition = character.PrimaryPart.Position
		end)

		while task.wait(0.5) and character:IsDescendantOf(workspace) do
			local newDistance = (character.PrimaryPart.Position - previousPosition).Magnitude

			if newDistance >= 0.1 then
				totalDistance += newDistance
			end

			player:WaitForChild("Quest"):WaitForChild("CurrentQuests"):WaitForChild("PathFinder"):WaitForChild("QuestPercent").Value = math.floor(totalDistance)
			previousPosition = character.PrimaryPart.Position
		end
	end)
end)

server script to edit datastores and give reward to the quest

--// Leaderstats

local rs = game:GetService("ReplicatedStorage")
local remotes = rs:WaitForChild("QuestRemotes")

-------------------------------------------------------

--// Quest Handler - Walk500Studs

remotes:WaitForChild("Walk500Studs"):WaitForChild("GiveQuest").OnServerEvent:Connect(function(player)
	print("pirnteddddd")
	local current = player:WaitForChild('Quest'):WaitForChild('CurrentQuests')
	local WalkStuds = Instance.new("Folder", current)
	WalkStuds.Name = "PathFinder"
	
	local quest = Instance.new("StringValue", WalkStuds)
	quest.Name = "Quest"
	
	local questTask = Instance.new("StringValue", WalkStuds)
	questTask.Name = "QuestTask"
	
	local questPercent = Instance.new("StringValue", WalkStuds)
	questPercent.Name = "QuestPercent"
	
	local questReward = Instance.new("StringValue", WalkStuds)
	questReward.Name = "QuestReward"
	
	local questGiver = Instance.new("StringValue", WalkStuds)
	questGiver.Name = "QuestGiver"
	
	local questdone = Instance.new("BoolValue", WalkStuds)
	questdone.Name = "QuestDone"
	
	----------
	--// Values
	quest.Value = "Path Finder"
	questTask.Value = "Walk 500 Studs"
	questReward.Value = "350"
	questGiver.Value = "Explorer"
	print("yayyy")
end)

remotes:WaitForChild("Walk500Studs"):WaitForChild("QuestDone").OnServerEvent:Connect(function(player)
	workspace.Quests.Walk500Studs.Enabled = false
	local path = player:WaitForChild('Quest'):WaitForChild('CurrentQuests'):WaitForChild('PathFinder')
	path:WaitForChild('QuestPercent').Value = "500"
	path:WaitForChild("QuestDone").Value = true
end)

remotes:WaitForChild("Walk500Studs"):WaitForChild("GivePrize").OnServerEvent:Connect(function(plr)
	local leader = plr:WaitForChild("leaderstats"):WaitForChild("EggCoins")
	leader.Value += 350
end)

local script to give the quest. And delete itself when the quest is done

local player = game.Players.LocalPlayer

local pathfinder = player:WaitForChild("Quest"):WaitForChild("CurrentQuests"):WaitForChild("PathFinder")
print("ok")
local scrollingframe = script.Parent.Parent.Parent:WaitForChild("QuestsFrame"):WaitForChild("QuestsScrollingFrame")
local questtemp = script.Parent.Parent.Parent:WaitForChild("Handler"):WaitForChild("QuestTemplate")
local handler = script.Parent.Parent.Parent:WaitForChild('Handler')
questtemp.Parent = scrollingframe
local quest = scrollingframe:WaitForChild("QuestTemplate"):Clone()
print("ok2")
quest.Parent = scrollingframe
print("ok3")
quest.Name = "QuestTemplate"
print("ok4")
quest.Visible = true
questtemp.Parent = handler
print("ok5")
quest.QuestName.Text = pathfinder:WaitForChild("Quest").Value
quest.QuestTask.Text = pathfinder:WaitForChild("QuestTask").Value
quest.QuestGiver.Text = pathfinder:WaitForChild("QuestGiver").Value
quest.Reward.Text = "$"..pathfinder:WaitForChild("QuestReward").Value
print("dragon")
while wait(0.1) do
	quest.ProgressText.Text = pathfinder:WaitForChild("QuestPercent").Value.."/500"
end

if player:WaitForChild("Quest"):WaitForChild("CurrentQuests"):WaitForChild("PathFinder"):WaitForChild("QuestPercent").Value >= 500 then
	quest.ProgressText.Text = "500"
	game.ReplicatedStorage.QuestRemotes.Walk500Studs.QuestDone:FireServer()
	script.Disabled = true
end

please help :pleading_face:

2 Likes

Hey there! It looks like you’re having trouble with your quest system and getting the quest to recognize when the player has walked 500 studs. I’d be happy to assist you with that.

The issue could be with the condition check in your code. When comparing the QuestPercent value to 500, the comparison doesn’t work as expected because Value returns a string, not a number.

To fix this, we can convert the Value to a number before comparing it. Here’s an updated version of the code that should resolve the problem:

while wait(0.1) do
	local questPercent = tonumber(pathfinder:WaitForChild("QuestPercent").Value)
	quest.ProgressText.Text = questPercent .. "/500"
	
	if questPercent >= 500 then
		quest.ProgressText.Text = "500"
		game.ReplicatedStorage.QuestRemotes.Walk500Studs.QuestDone:FireServer()
		script.Disabled = true
	end
end

By using the tonumber() function, we can convert the Value string into a number that can be compared correctly.

I hope this somewhat helps!

Hey! Tried this out and it works! Although…


I don’t know how to disable the old dialouge. I tried so many stuff.

That’s great to hear that my previous idea worked! Now, regarding the issue with disabling the old dialogue, could you please let me know what you’ve already tried? I’d be happy to help you find a solution!

Well i tried making a inscript value called QuestDone (inside the script, variable.)
It would be set as false, and when the player completed the quest it would be true, disabling the old dialouge and implementing the new one, Though I tried it and didnt work.

One problem with this is duplication. Example: You have the quest Walk 500 studs. You can still talk to the stud, and get another quest.

I have one approach that might work in mind!
Within your script, locate the section where the old dialogue is displayed. After setting db to false, add the following lines of code:

if player:WaitForChild("Quest"):WaitForChild("CurrentQuests"):WaitForChild("PathFinder"):WaitForChild("QuestDone").Value == true then
    beforegui.Enabled = false -- Disable the old dialogue GUI
    -- Add code here to perform any necessary actions
end

By incorporating these lines of code, I think the old dialogue GUI will be disabled when the QuestDone variable is set to true.

Oh whoops… my fault I thought you meant the old dialouge.

Although the new dialouge uses the same gui…


I tried it but it didnt work. I used a different gui but it still wont work???

print("hey guyssyfuihewfiuhewfiuwf")
local explorer = workspace["QUEST NPCS"].Part
local player = game.Players.LocalPlayer
local beforegui = player.PlayerGui:WaitForChild("QuestDialouge")
local gui = beforegui:WaitForChild("QuestDialogue")
local othergui = player.PlayerGui:WaitForChild("QuestDialougeDone")
local questdone = false

print("beforegui looolll")
local db = false
print("Hey guys whats up today so im going to say hello")
explorer.Touched:Connect(function()
	if not db then
		db = true
		print("2")
		beforegui.QuestDialogue.Visible = true
		print("3")
	gui.NPCName.Text = "Part"
	local chatText = "Hey! I need you to explore this island for me, I need approximately 500 studs explored before I can uncover the mystery of this island, I hear theres a strange thing below here! Will you help me?"
	for i = 1, string.len(chatText) do
		wait(0.025)
		gui.Dialogue.Text = string.sub(chatText, 1, i)
			script.Parent.Parent.Sound:Play()
		end
		gui.Option1.Text = "Sure!"
		gui.Option2.Text = "Nope, I don't want to."
		gui.Option1.Visible = true
		gui.Option2.Visible = true
		print("4")
			db = false
	end
end)

gui.Option1.MouseButton1Click:Connect(function()
	gui.Option1.Visible = false
	gui.Option2.Visible = false
	local chatText = "Thanks man!"
	for i = 1, string.len(chatText) do
		wait(0.025)
		gui.Dialogue.Text = string.sub(chatText, 1, i)
		script.Parent.Parent.Sound:Play()
	end
    wait(2)
	beforegui.QuestDialogue.Visible = false
	game.ReplicatedStorage.QuestRemotes.Walk500Studs.GiveQuest:FireServer()
	wait(2)
	script.Parent.GiveQuest.Enabled = true
end)

gui.Option2.MouseButton1Click:Connect(function()
	gui.Option1.Visible = false
	gui.Option2.Visible = false
	local chatText = "You don't want to? Well.. If you change your mind come to me, I'm waiting for you here."
	for i = 1, string.len(chatText) do
		wait(0.025)
		gui.Dialogue.Text = string.sub(chatText, 1, i)
		script.Parent.Parent.Sound:Play()
	end
	wait(2)
	beforegui.QuestDialogue.Visible = false
	game.ReplicatedStorage.QuestRemotes.Walk500Studs.GiveQuest:FireServer()
	wait(1)
end)

local eb = false

explorer.Touched:Connect(function()
	if player:WaitForChild("Quest"):WaitForChild("CurrentQuest"):WaitForChild("PathFinder"):WaitForChild("QuestDone").Value == true and questdone == true then
		if not eb  then
			eb = true
			beforegui.Enabled = false
			othergui.QuestDialogue.Visible = true
			local chatText = "Whoa! Thats a bunch of information! Thank you"..player.Name.."If thats your name. Goodbye!"
			for i = 1, string.len(chatText) do
				wait(0.025)
				othergui.QuestDialogue.Dialogue.Text = string.sub(chatText, 1, i)
				script.Parent.Parent.Sound:Play()
			end
			wait(2)
			game.ReplicatedStorage.QuestRemotes.Walk500Studs.GivePrize:FireServer()
			othergui.QuestDialogue.Visible = false
		end
	end
end)

image

Hi can anyone help with this? pls?

Please. help please. Im still having this problem