Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Error coming from valid line?

Asked by 3 years ago

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.

0
Btw, I tried another while wait() loop without wnything in it. Still gave me the same error. TheB4dComputer 100 — 3y
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 Spjureeedd 385 — 3y
0
^^ while true do with a wait() and while wait() do is the same thing Omq_ItzJasmin 666 — 3y
0
Still didn't work... gave me the same error. TheB4dComputer 100 — 3y
View all comments (9 more)
0
Well what line then? Spjureeedd 385 — 3y
0
Maybe your script is too messy. Maybe try a module script? Finty_james 269 — 3y
0
Even with the Module script it gave me the same error TheB4dComputer 100 — 3y
0
The error is from the wait TheB4dComputer 100 — 3y
0
Put a interger in the wait.. I dont how thats going to work but I hope it does Finty_james 269 — 3y
0
when i mean interger i mean number Finty_james 269 — 3y
0
Maybe use a variable in the script to hold the value instead of a Instance to hold the value Finty_james 269 — 3y
0
So you dont have to waste more time searching for the Instance that holds the cerain value. Finty_james 269 — 3y
0
Also File Space too Finty_james 269 — 3y

2 answers

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
3 years ago

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
Ad
Log in to vote
0
Answered by 3 years ago

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.

0
Sorry for the late response. I figured the error part out a while ago but thanks for the improved script! TheB4dComputer 100 — 3y

Answer this question