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

Error coming from valid line?

I've been trying to make a script where where, every so often, a crystal will spawn in the bounds of the map. I have a while wait() loop in a script. The script is in ServerScriptService. The error is coming from the loop and says: "Requested Module is Required Recursively". My code:

local Rate = script.resourceRate
local MaxSpawn = Vector3.new(218.44, 0.5, -227.733)
local MinSpawn = Vector3.new(-228.008, 0.5, 223.37)
print("Localled")
while wait(math.exp(Rate.Value))do
	print("Making")
	local Crystal = game.ServerStorage.Crystal:Clone()
	Crystal.Parent = workspace
	Crystal.CFrame = math.random(Vector3.new(218.44, 0.5, -227.733), Vector3.new(-228.008, 0.5, 223.37))
end

Anybody have an idea on how to fix this? It's never happened before.

13 comments

0

Btw, I tried another while wait() loop without wnything in it. Still gave me the same error.

0

Just don't do while wait() do. I honestly don't see why people do that. Do it like you should, while true do. And then have a wait() inside your loop

0

^^ while true do with a wait() and while wait() do is the same thing

0

Still didn't work... gave me the same error.

0

Well what line then?

0

Maybe your script is too messy. Maybe try a module script?

0

Even with the Module script it gave me the same error

0

The error is from the wait

0

Put a interger in the wait.. I dont how thats going to work but I hope it does

0

when i mean interger i mean number

0

Maybe use a variable in the script to hold the value instead of a Instance to hold the value

0

So you dont have to waste more time searching for the Instance that holds the cerain value.

0

Also File Space too

2 answers

✓ Accepted answer

The error is not coming from your code: it's pretty obvious that you aren't requiring any module script, let alone recursively requiring a module within the module itself. The error is most likely thrown by roblox's built-in building tools

There is, however, an issue with your code, most likely unseen because of the output being spammed by the same error message from roblox's built-in building tools: math.random can only accept numbers and it'll error otherwise. Here's what your solution would look like:

local Rate = script.resourceRate
local MaxSpawn = Vector3.new(218.44, 0.5, -227.733)
local MinSpawn = Vector3.new(-228.008, 0.5, 223.37)

print("Localled")

-- Return a random floating point number (decimal number) since math.random doesn't accept nor return floats
function randomFloat(n, m)
    return math.random() * (m - n) + n
end

while wait(math.exp(Rate.Value))do
    print("Making")
    local Crystal = game.ServerStorage.Crystal:Clone()
    Crystal.Parent = workspace
    Crystal.CFrame = CFrame.new(
        randomFloat(MinSpawn.X, MaxSpawn.X),
        0.5,
        randomFloat(MaxSpawn.Z, MinSpawn.Z)
    )
end

Use a variable in the script. Instead of using an instance to hold that value, you can use variables to hold that value. Plus, It gives less memory of the file. Also, you can just do this:

	local Rate = -- your value -- (number)
local MaxSpawn = Vector3.new(218.44, 0.5, -227.733)	local MinSpawn = Vector3.new(-228.008, 0.5, 223.37)
print("Localled")
while wait(math.exp(Rate))do
    print("Making")
    local Crystal = game.ServerStorage.Crystal:Clone()	    Crystal.Parent = workspace    Crystal.CFrame = math.random(Vector3.new(218.44, 0.5, -227.733), Vector3.new(-228.008, 0.5, 223.37))
	end

I hope that helped.

1 comment

0

Sorry for the late response. I figured the error part out a while ago but thanks for the improved script!

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