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