It’s not really a big project, I’m just refining my skills, but I’m making a simple ball merging game but this one script keeps crashing my computer. I’ve had scripts of infinite loops that caused delays in playtesting and threw errors like “blah blah script exhausted allowed execution time” but this script has short waits in-between runs and it completely crashes Roblox Studio, where I have to re-open it.
Here’es the script.
-- Access the script's ball
local Ball = script.Parent
-- Merge function
local functions = require(workspace.Scripts.BallFunctions)
-- Merge cooldown
local cooldown = 5
-- Check if balls are merging
Ball.Touched:Connect(function(Part)
if Part.Name == "Ball" and cooldown == 0 then
functions.Merge(Ball, Part)
cooldown = 5
end
end)
-- Decrease the cooldown
while true do
if cooldown > 0 then
wait(1)
cooldown-=1
end
wait(0.1)
end
IF you aren’t going to display the cooldown (ex: have the cooldown on a gui, use this:)
-- Access the script's ball
local Ball = script.Parent
-- Merge function
local functions = require(workspace.Scripts.BallFunctions)
-- Merge cooldown
local cooldown = false
-- Check if balls are merging
Ball.Touched:Connect(function(Part)
if Part.Name == "Ball" and cooldown == false then
cooldown = true
functions.Merge(Ball, Part)
task.delay(5, function()
cooldown = false
end)
end
end)
However, if you do need to display the cooldown or have it count down,
-- Access the script's ball
local Ball = script.Parent
-- Merge function
local functions = require(workspace.Scripts.BallFunctions)
-- Merge cooldown
local cooldown = 5
-- Check if balls are merging
Ball.Touched:Connect(function(Part)
if Part.Name == "Ball" and cooldown == 0 then
functions.Merge(Ball, Part)
cooldown = 5
repeat cooldown-=1; task.wait(1)
until cooldown == 0
end
end)