That’s my code but when the quest is accepted the code won’t go down to the “questAccepted” lines.
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local player = Players.LocalPlayer
local npc = script.Parent.Head
local debounce = false
local questAccepted = false
local interact = script.Parent.Interact
interact.MouseClick:Connect(function()
if debounce then return end
debounce = true
if not questAccepted then
if questAccepted then return end
Chat:Chat(npc, "Hey man, I'm starving!", "White")
wait(2)
Chat:Chat(npc, "Could you go get me some berries?", "White")
debounce = false
interact.MouseClick:Connect(function(player)
if questAccepted then return end
debounce = true
questAccepted = true
local quests = player:WaitForChild("Quests")
local berriesCollected = Instance.new("IntValue", quests)
berriesCollected.Name = "berriesCollected"
Chat:Chat(npc, "Thanks man, you're a life saver!", "White")
end)
if questAccepted then
local berriesCollected = player.Quests.berriesCollected
if berriesCollected.Value > 6 then
Chat:Chat(npc, "C'mon man, hurry up with the berries!", "White")
else
Chat:Chat(npc, "Thanks for the berries man!", "White")
berriesCollected:Destroy()
end
end
end
end)
1 Like
I think you are missing an “end” somewhere. It looks like if the quest is not accepted it will skip the entire function, which im gussing is not what you want. I marked the changes in the code below. I hope this was helpfull
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local player = Players.LocalPlayer
local npc = script.Parent.Head
local debounce = false
local questAccepted = false
local interact = script.Parent.Interact
interact.MouseClick:Connect(function()
if debounce then return end
debounce = true
if not questAccepted then
if questAccepted then return end
Chat:Chat(npc, "Hey man, I'm starving!", "White")
wait(2)
Chat:Chat(npc, "Could you go get me some berries?", "White")
debounce = false
interact.MouseClick:Connect(function(player)
if questAccepted then return end
debounce = true
questAccepted = true
local quests = player:WaitForChild("Quests")
local berriesCollected = Instance.new("IntValue", quests)
berriesCollected.Name = "berriesCollected"
Chat:Chat(npc, "Thanks man, you're a life saver!", "White")
end)
end -- HERE
if questAccepted then
local berriesCollected = player.Quests.berriesCollected
if berriesCollected.Value > 6 then
Chat:Chat(npc, "C'mon man, hurry up with the berries!", "White")
else
Chat:Chat(npc, "Thanks for the berries man!", "White")
berriesCollected:Destroy()
end
end
--end This one should be removed
end)