Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this script repeat this function 2X?

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

0

Unless you want decimals (eg 0.1, 0.12345, etc), i suggest using IntValues. Intergers are whole numbers, meaning no decimals and stuff

0

just do wait() at line 10 instead of wait(5). when you wait(5), another loop is done, making the script happen twice

1 answer

idk if this is the problem, but...

It wait 5 seconds before it destroys itself while it is waiting the loop happens again Make the number on line 03 not be equal to the number on line 10.

This discussion is preserved as it was. New answers, comments, and votes are closed.