Why the heck does my script keep exhausting itself, and how do I prevent the script timeout?

I’ve been actively trying to fix an error that would just cause my script to fail, It’s very frustrating and Im not even being told the actual problem.

It keeps saying that on line 16, the script is timing out

  15:26:03.365  Script timeout: exhausted allowed execution time  -  Server - Spawner:16
  15:26:03.365  Stack Begin  -  Studio
  15:26:03.365  Script 'Workspace.BallSpawner.Spawner', Line 16  -  Studio - Spawner:16
  15:26:03.365  Stack End  -  Studio

I’ve tried adding a debounce, but its still not working.

Script

local RS = game:GetService("ReplicatedStorage")

local Ball = RS:WaitForChild("Objects"):WaitForChild("Ball")

local RespawnTime = script.Parent:WaitForChild("RespawnTime").Value

local Debounce = false

while true do
	if Debounce == false then Debounce = true

	local BallClone = Ball:Clone() 
	BallClone.Parent = workspace
	BallClone.CFrame = script.Parent.CFrame

	local V = BallClone:WaitForChild("LinearVelocity") -- Line 16
	task.wait(1)
	V.Enabled = true

	local X = math.random(-1,1) * 15

	if X == 0 then
		V.VectorVelocity = Vector3.new(X,0,math.random(-1,1) * 15)
	else
			V.VectorVelocity = Vector3.new(X,0,0)
		end
	end
	
	task.wait(RespawnTime)
	
	Debounce = false
end

Try printing RespawnTime. What does it say?

Switch your script to this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local Ball = ReplicatedStorage:WaitForChild("Objects"):WaitForChild("Ball")
local Parent = script.Parent
local RespawnTime = Parent:WaitForChild("RespawnTime").Value

--//Controls
local Debounce = false

--//Loops
while true do
	if not Debounce then
		Debounce = true
		
		local BallClone = Ball:Clone() 
		BallClone.CFrame = Parent.CFrame
		BallClone.Parent = workspace

		local V = BallClone:WaitForChild("LinearVelocity")
		
		task.wait(1)
		V.Enabled = true

		local X = math.random(-1, 1) * 15

		if X == 0 then
			V.VectorVelocity = Vector3.new(X, 0, math.random(-1, 1) * 15)
		else
			V.VectorVelocity = Vector3.new(X, 0, 0)
		end
		
		task.wait(RespawnTime)
		Debounce = false
	end
end

Thanks for the script but, it would be nice if you can explain to me how you fixed it.

Also, Im still getting an error where it says

local V = BallClone:WaitForChild("LinearVelocity")

It’s because you added the wait outside of the if debounce instead of waiting inside the if debounce.

Are you sure the ballclone has a child called LinearVelocity? Add one if it doesn’t.