So I'm making a simple quest where a player has to destroy 10 targets around the arena, each time a target is destroyed it updates a number value in a configuration. Once the value reaches 10 this script plays a function, here's the script:
local targetsDestroyed = game.Workspace.Quests.BattleTraining.TargetsDestroyed
while wait(5) do
if (targetsDestroyed.value > 9) then
----------------------------this is the function-----------------------
local m = Instance.new("Message")
m.Parent = game.Workspace
m.Text = "Quest Complete: Destroy Targets In The Arena"
game.ServerStorage.PlayerMoney:FindFirstChildOfClass("NumberValue").Value = game.ServerStorage.PlayerMoney:FindFirstChildOfClass("NumberValue").Value + 1000
wait(5)
m:Destroy()
script.Parent:Destroy()
--------------------end of the function--------------------------------------
end
end
the function works but the problem is that the function happens twice before the script is destroyed, can someone help me fix this?

2 comments
Unless you want decimals (eg 0.1, 0.12345, etc), i suggest using IntValues. Intergers are whole numbers, meaning no decimals and stuff
just do wait() at line 10 instead of wait(5). when you wait(5), another loop is done, making the script happen twice