Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make dialogue only appear once a quest is completed?

Asked by 6 years ago

I made this quest system and along with it, a dialogue system. I made the dialogue to work so when you touch a part then a gui would pop up with a dialogue prompt. It functions fine but I only want the dialogue to appear when a specific quest has been completed.

Quest Completion Marker(for reference of how the mission becomes assigned complete):

script.Parent.Touched:connect(function(touchedpart)
local player = game.Players:GetPlayerFromCharacter(touchedpart.Parent)

if player then
if player:FindFirstChild("Quest6") and player:FindFirstChild("Quest6").Value == "-[Get a Water Tank]" then
player.Quest6.Value = "-[Completed]"
game.Workspace.Data[player.Name].Socks.Value = game.Workspace.Data[player.Name].Socks.Value + 1

        end

    end

 end)

Dialogue System:

local debounce = false

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent:clone().Parent = player.PlayerGui
wait(17)
debounce = false
player.PlayerGui.OnTouchGui:remove()
wait()
debounce = false
wait(17)
end
end


script.Parent.Parent.Touched:connect(onTouch) 

1 answer

Log in to vote
0
Answered by 6 years ago

Use your ingame debounce.

It seems that you have a quest completion debounce in your game. It may be a string value or something. Try replacing it with a BoolValue instead.

script.Parent.Touched:connect(function(touchedpart)
local player = game.Players:GetPlayerFromCharacter(touchedpart.Parent)

if player then
if player:FindFirstChild("Quest6") and player:FindFirstChild("Quest6").Value == false -- for for not completed
player.Quest6.Value = true -- sets it to true/completed
game.Workspace.Data[player.Name].Socks.Value = game.Workspace.Data[player.Name].Socks.Value + 1

        end

    end

 end)

Now you modify your second script to use the Bool.

local debounce = false
function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 
local human = part.Parent:findFirstChild("Humanoid") 
local player = game.Players:GetPlayerFromCharacter(part.Parent) -- added in for compatibility
local questbool = player:FindFirstChild("Quest6").Value -- the new bool
if (human ~= nil) and debounce == false and questbool = true then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent:clone().Parent = player.PlayerGui
wait(17)
debounce = false
player.PlayerGui.OnTouchGui:remove()
wait()
debounce = false
wait(17)
end
end


script.Parent.Parent.Touched:connect(onTouch) 

I hope this helped you in the right sense. Good luck!

Ad

Answer this question