|
| 31 Jul 2013 12:18 AM |
The script, for the most part, works. However I want to make it not spawn a log in the same place twice. This can get very annoying because it makes things fly everywhere.
So how do I make it spawn in different places and never the same twice?
Also, it still spawns logs even if there are more than 10 in the model named "Logs"
how do I fix that?
code V V V
logMakers = {script.Parent.LogMaker1,script.Parent.LogMaker2,script.Parent.LogMaker3, script.Parent.LogMaker4} numLogs = script.Parent.Logs:getChildren() print("loaded") while #numLogs <= 10 do print("loop began") randA = math.random(3,8) randB = math.random(1,3) print(randA .. ":wait, times: " .. randB) for i = 1, randB do randC = (math.random(1,25))/10 randLog = logMakers[math.random(1, #logMakers)] print("-------------------") print(randLog) print("-------------------") newLog = game.Lighting.Log:clone() newLog.Parent = script.Parent.Logs newLog.Torso.CFrame = randLog.CFrame wait(randC) end wait(randA) end |
|
|
| Report Abuse |
|
|
clc02
|
  |
| Joined: 30 Dec 2007 |
| Total Posts: 7393 |
|
|
| 31 Jul 2013 01:29 AM |
It's still spawning more than ten because you get the number spawned before the loop so it does: Check for logs, 0 did the check say less than ten logs? (0) Yes spawn log did the check say less than ten logs? (0) yes spawn log repeat ad nausem.
logMakers = {script.Parent.LogMaker1,script.Parent.LogMaker2,script.Parent.LogMaker3, script.Parent.LogMaker4} numLogs = script.Parent.Logs:getChildren() print("loaded") while #numLogs <= 10 do print("loop began") randA = math.random(3,8) randB = math.random(1,3) print(randA .. ":wait, times: " .. randB) for i = 1, randB do randC = (math.random(1,25))/10 --Started change here newlog = math.random(1,#logMakers) while newlog==oldlog do newlog=math.random(1,#logMakers) end oldlog=newlog randLog = logMakers[newlog] -- print("-------------------") print(randLog) print("-------------------") newLog = game.Lighting.Log:clone() newLog.Parent = script.Parent.Logs newLog.Torso.CFrame = randLog.CFrame wait(randC) end wait(randA) numLogs = script.Parent.Logs:getChildren() end
That'll stop more than ten spawning. It'll also stop a log from spawning at the same spot twice in a row. It keeps track of which log spawner was used last time and keeps retrying till it gets a new one if it randoms the same one as last time until it has a new one. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2013 01:55 AM |
| Thanks a ton, I really learned a lot through this |
|
|
| Report Abuse |
|
|