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

Why does this script consistently crash studio?

This is my first code after about a 7 month hiatus, so I'm expecting there's some stupid mistake causing this. Whenever I run this script (play or just the regular run, both within studio) it loads the place half way, then the entire thing stops, and without any output or error messages, it freezes permanently and I have to use task manager to close it.

I have marked the line that seems to be the issue (if I purposely make a mistake, such as a lowercase "V" in value, it doesn't crash). Everything above this line runs just fine. Because of this strange catch, I'm not sure if it's an issue with my code or with the software, but my code is the only thing I can double check.

Thanks for reading, and here's the code (if you need any additional info, just leave a comment) --

local x = script.Parent.Position.X; -- hierarchy is Block --> Initrun(bool value), Script(this script) --> MaxDistance(number value), closeMultiplier(number value)
local y = script.Parent.Position.Y + 4;
local z = script.Parent.Position.Z;

local mdist = script.MaxDistance.Value;
local limitnum = mdist * script.closeMultiplier.Value;
local xs = script.Parent.Size.X;
local zs = script.Parent.Size.Z;
local initial = script.Parent.Initrun.Value;

local waittime = game.Lighting.ototal.respawn.Value; -- an integer value

local limit;

repeat -- the true start

if initial == false then
	limit = math.floor(((zs + xs)/2)/limitnum); -- creates the aforementioned "local limit"
	print(limit);
	initial = true;
	elseif game.Lighting.ototal.Value > limit then -- Integer value, I also suspect this is the line causing issues.
		wait(waittime)
	else
	ospawn()
end

function ospawn()
	print("Spawned!")
end

until nil 

1 answer

✓ Accepted answer

You're using a repeat statement with conditionals inside.. one one out of three of these has a wait in the code so if the other two conditions are ever met then, since there's no yield it will repeat the code infinitely and crash your studio. Also, you're not defining ospawn before calling it. It will return nil since it's an if statement. You have to define ospawn before trying to call it!

So define ospawn before calling it and add in those yields.

local x = script.Parent.Position.X; -- hierarchy is Block --> Initrun(bool value), Script(this script) --> MaxDistance(number value), closeMultiplier(number value)
local y = script.Parent.Position.Y + 4;
local z = script.Parent.Position.Z;

local mdist = script.MaxDistance.Value;
local limitnum = mdist * script.closeMultiplier.Value;
local xs = script.Parent.Size.X;
local zs = script.Parent.Size.Z;
local initial = script.Parent.Initrun.Value;

local waittime = game.Lighting.ototal.respawn.Value; -- an integer value

local limit;

function ospawn()
    print("Spawned!")
end

repeat -- the true start

if initial == false then
    limit = math.floor(((zs + xs)/2)/limitnum); -- creates the aforementioned "local limit"
    print(limit);
    initial = true;
    elseif game.Lighting.ototal.Value > limit then -- Integer value, I also suspect this is the line causing issues.
        wait(waittime)
    else
	wait(waittime)
    ospawn()
end

until nil 

1 comment

0

Ah, I didn't see that. I got a bit ahead of myself with testing the script then, since I'll have ways to wait later on. As for the function, I've never had an issue calling one higher in the script than its creation -- I'll keep it in mind though! Thanks for the help.

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