Need help on quest script!

Hi, I am making a quest script and line 23, I will note where it is is not working. It just says an error on line 23 and nothing else.

script.Parent.Triggered:Connect(function(player)
	local QuestGiver = math.random(1, 2)
	local HasQuest = Instance.new("NumberValue")
	HasQuest.Parent = player
	HasQuest.Name = "HasQuest"
	HasQuest.Value = 0
	
	if QuestGiver == 1 then
		if HasQuest.Value == 0 then
			HasQuest.Value += 1
			
			print("1")
			-- This quest is to get 100 coins and win 100 coins.
			local Count = Instance.new("IntValue")
			Count.Name = "Count"
			Count.Value = 0
			Count.Parent = player

			local leaderstats = player.leaderstats
			local Coins = leaderstats.Coins
			local PastCoinValue = Coins.Value

			task.wait(Coins.Value == PastCoinValue + 100) -- error here

			Coins.Value += 100
			HasQuest -= 1
		else
			return
		end
	end
	
	if QuestGiver == 2 then
		if HasQuest == 0 then
			HasQuest += 1
			print("2")
			-- This quest is to kill (X) amount of bots
			local X = 5 -- X = number of bots to kill
			local KillCounter = Instance.new("NumberValue")
			KillCounter.Name = "KillCounter"
			KillCounter.Value = 0
			KillCounter.Parent = player

			task.wait(KillCounter.Value == X)
			HasQuest -= 1
		else
			return
		end
	end
end)

Can someone help please? I still need help.

why is this inside a task.wait?

task.wait() takes in a number not an if statement

should it be wait() instead?

So I did wait() but now it just plays through instead of waiting until the code inside the brackets is played.

I still need help, I am trying to figure it out though.

Bumping.

task.wait() is to wait an amount of time
to wait lets say something like 2 seconds (change it as you wish)
do
task.wait(2)
then you could do

if Coins.Value == PastCointValue + 100 then
    Coins.Value += 100
    HasQuest -= 1
end

also you should probably use a bool(true/false) instead of an int on HasQuest.

1 Like
task.wait(Coins.Value == PastCoinValue + 100) -- error here

You’re passing a Boolean value to task.wait which is incorrect.

task.wait(true) --Errors.

The same issue will also occur here.

task.wait(KillCounter.Value == X)

Is this what you’re trying to achieve?

if KillCounter.Value == X then
	task.wait(X)
end

No the point is you wait until the value is equal to another value.

dude
errors break your code…
If you insist on making it like that wrap it in a pcall

yes I know that the error is in line 26 didn’t I say that?

Boolean values are true or false

Number values are well numbers

whats true + 100
you don’t know do you?

nether does the code so it errors

what if I said its an IntValue :magic_wand:

Tell me
what does this print

print(100 == 100)

it prints true
YOU ARE MAKING A BOOLEAN VALUE THEN ADDING TO IT…

Can you please show where?

Alright let me do a in depth explanation
task.wait is a function that only takes numbers

Coins.Value is a number and so is PastCoinValue
If you compare them in a script they will make a true or false value
you are adding 100 to that value
then putting it into task.wait

I know, I said I changed it to wait and a new problem occurred.

tell me what your trying to do in that line of code
check if they equal eachother if so wait 100 seconds?

WAIT ISN’T A IF CHECK NETHER IS TASK.WAIT
this is a beyond backwards scripting knowledge