Script stopping whenever task.wait()

The main problem is that my script completely stops running once I try to run task.wait() or wait(). It isn’t in all scripts though, only this one script and any modules I call from it. I am doing nothing out of the ordinary in that script. Just the usual calling modules, local functions, variables, ect.

Here is what’s happening (note: this is only a section of the script):

print("waiting 1")
task.wait(1)
print("wait complete")
-- I then go on to call a module
RigModule.Attack((Die.Parent.Parent.RigSpawn:GetChildren()[1]), (target.Parent.RigSpawn:GetChildren()[1]), ValueNumber)
-- Anytime I use task.wait in this module function it also stops the script

the output (ignore the other stuff from different scripts):


No errors. It simply stopped.

THE MOST COFUSING PART
This was not happening before! I reverted back to a version that I KNOW FOR A FACT did not act up.

The full script
-- Modules
local gameModules = ServerScriptService:WaitForChild("GameModules")
local Main = require(gameModules.Main)
local Resolve = require(gameModules.Resolve)
local Dice = require(gameModules.DiceModule)
local RigModule = require(gameModules.RigModule)
-- Variables
local Area = script.Parent
local Die = Area.Parent
local click = Area:WaitForChild("ClickDetector")
local clickMode = Die.Parent.Parent:FindFirstChild("ClickMode")
local ActionsFolder = Die.Parent.Parent.Parent.ActiveFunctions
-- Colors
local Red = Color3.new(0.839216, 0, 0.0117647) -- Damage
local Blue = Color3.new(0.0941176, 0.639216, 1) -- Shield
local Orange = Color3.new(1, 0.670588, 0.294118) -- Resource
local White = Color3.new(255,255,255) -- Blank
local Black = Color3.new(0.14902, 0.14902, 0.14902) -- Disrupt
local Green = Color3.new(0.32549, 0.756863, 0) -- Focus (change side)
local DarkBlue = Color3.new(0.00392157, 0.160784, 0.498039) -- Ability
local Yellow = Color3.new(0.823529, 0.831373, 0.27451) -- Discard

-- local functions here

click.MouseClick:Connect(function(player)
	if player.SideNumber.Value == tonumber((string.gsub(Die.Parent.Parent.Parent.Name, "Side", ""))) and clickMode.Value == 1 then
		local Side = Die.Parent.Parent.Parent
		-- Change click mode for cards/characters
		Main.ChangePlayerClickMode(0, player.SideNumber.Value, Side.Parent, false)
		
		-- Add the action value to the action folder
		local value = Instance.new("StringValue", Side.ActiveFunctions)
		value.Name = "DiceResolve"
		
		-- Raise the dice
		if Die.PrimaryPart:FindFirstChild('BodyVelocity') then
			Die.PrimaryPart.BodyVelocity.Velocity = Vector3.new(0,2,0)
		else
			local velocity = Instance.new("BodyVelocity",Die.PrimaryPart)
			velocity.Velocity = Vector3.new(0,10,0)
			velocity.MaxForce = Vector3.new(4000,100000,4000)
		end
		
		task.wait(1)
		-- Stop raising dice
		Die.PrimaryPart.BodyVelocity.Velocity = Vector3.new(0,0,0)
		
		-- Get the value/damage type
		local ValueTypeTable = Dice.GetValueTypeFromTopDieSide(Die)
		local ValueType = ValueTypeTable[1]
		local ValueNumber = ValueTypeTable[2]
		local Color
		local target
		
		if ValueType then
			if ValueType == "Melee" or ValueType == "Ranged" or ValueType == "Indirect" then
				Color = Red
				local valid = {"characters", "enemy" , ValueNumber}
				local Effect = CreateEffect(Color)
				target = Resolve.PromptSelect(player, valid)
				TweenEffect(Effect, target)
				print("waiting 1")
				wait(1)
				print("wait complete")
				RigModule.Attack((Die.Parent.Parent.RigSpawn:GetChildren()[1]), (target.Parent.RigSpawn:GetChildren()[1]), ValueNumber)
			elseif ValueType == "Resource" then
				Color = Orange
				local Effect = CreateEffect(Color)
				target = Resolve.GainResource(player, Main.GetOpponentPlayer(player), ValueNumber)
				TweenEffect(Effect, target, "explode")
			elseif ValueType == "Shield" then -- NOTE: add shield effects once characters are created
				Color = Blue
				local valid = {"characters", "friendly", ValueNumber}
				local Effect = CreateEffect(Color)
				target = Resolve.PromptSelect(player, valid)
				Resolve.GiveShields(player, target, ValueNumber)
				TweenEffect(Effect, target)
			elseif ValueType == "Discard" then
				Color = Yellow
				local valid = {"cards", "enemy", ValueNumber}
				local Effect = CreateEffect(Color)
				local target = Resolve.PromptSelect(player, valid) -- It actually removes the card from the opponent inside the prompt function
				TweenEffect(Effect, target, "explode")
			elseif ValueType == "Disrupt" then
				Color = Black
				local Effect = CreateEffect(Color)
				local Opponent = Main.GetOpponentPlayer(player)
				if player.Resources.Value - ValueNumber < 0 then
					ValueNumber = 0
				end
				local target = Resolve.GainResource(Opponent, player, -ValueNumber)
				TweenEffect(Effect, target, "explode")
			elseif ValueType == "ChangeSide" then
				Color = Green
				local Effect = CreateEffect(Color)
				local valid = {"dice", "friendly", ValueNumber}
				local target = Resolve.PromptSelect(player, valid)
				Resolve.ChangeDieSide(player, target)
				TweenEffect(Effect, target, "explode")
			elseif ValueType == "Ability" then-- WIP
				Color = DarkBlue
				CreateEffect(Color)
				local target = Main.CharacterAbility(Die.Parent.Parent)
			elseif ValueType == "Blank" then
				Color = White
				-- No function just have it tween the effect upward if there is no target also spread like fade
				local Effect = CreateEffect(Color)
				Effect:Destroy()
			end
		end	
		value:Destroy()
	end
end)

I excluded all local functions in this script because it would be to long. The problem area is in the final if statment right after If ValueType then

I don’t know if this is a bug, virus or something wrong with my studio. This is very frustrating for me and I’m out of ideas. Thank you for any replies or support!

1 Like

Have you checked that no other script is messing with that script after you click test by looking in the explorer to make sure it wasn’t disabled or deleted. That’s the only thing I can think of that would cause this behavior.

1 Like

i dont really know about a fix, but my friend recommend me to use task.wait(), so i started to rewrite waits to task.wait, and im facing same issue.

1 Like

Are you disabling or destroying the script? Recently a fix was released so scripts stop running with task.wait() if they get destroyed or disabled (since they didnt before)

2 Likes

Thank you so much! Now I can get back to working on my game!

1 Like