Constant error about math.random

Yeah no problem. I’m procrastinating on my homework so I don’t mind. Whats the request?

1 Like

ok so, i want to make trees spawn all over the map but i want it to stop at some point, i’d really appreciate your help

We can use a for loop. Parameter 1, where we start, Parameter 2, where we end, Parameter 3, how much to count by. Basically we start at 1 and count by 1 until we reach “desiredTrees”

local desiredTrees = 100

for i = 1, desiredTrees, 1 do
        --code here
end

is that a code you put up there? local Height = 5 wood.PrimaryPart = wood.MeshPart wood:SetPrimaryPartCFrame(CFrame.new(Vector3.new(math.random(-157, 249),Height, math.random(-157, 249))))

and i am really really sorry but i’ve got one more problem, i need to make a script so objects dont spawn inside something else (can put script manually in those obj)

What do you mean? Try something like this, just remember to define the “TreModel” variable.

local desiredTrees = 100
local TreeModel = --define here

for i = 1, desiredTrees, 1 do
       wait()
       local wood = TreeModel:Clone()
      wood.Parent = workspace
      local Height = 5
      wood.PrimaryPart = wood.MeshPart
       wood:SetPrimaryPartCFrame(CFrame.new(Vector3.new(math.random(-157, 249),Height, math.random(-157, 249))))
       for i, v in pairs(wood:GetDescendants()) do
              if v:IsA("BasePart") then
                 for ii, vv in pairs(v:GetTouchingParts()) do
                       if wood and not vv:FindFirstAncestor(wood) then
                           wood:Destroy()
                           break
                      end
                 end
            end
       end
end
1 Like

where do i put script? in my model[s] or no?

Put this script in ServerScriptService. Don’t forget to define the TreeModel variable

1 Like

'ServerScriptService.desiredTrees:13: Expected ‘(’, ‘{’ or when parsing function call, got ‘)’ ’

Recopy it, sorry I made a typo.

1 Like

as always, there’s an error
ServerScriptService.desiredTrees:4: Expected identifier when parsing expression, got ‘for’

Did you define what “TreeModel” was. You have to define the path to the tree model.

i actually forgot, now i did and it still says first error

Which error was the first one?

'ServerScriptService.desiredTrees:13: Expected ‘(’, ‘{’ or when parsing function call, got ‘)’ ’

So line 13 is exactly like this:

1 Like

its just spamming my output like a maniac with 2,4 numbers

I didn’t add any prints, why is it spamming the output. I gtg in a minute, maybe someone else can help you. You could post another topic and ask for help on the code.

1 Like

ok, sorry for taking your time, thanks for help

No problem at all, I’m glad to help :slight_smile: . I have like 2 minutes. So do the trees not spawn? Does it still have that error?

1 Like

no error, but trees do not spawn