generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Whats wrong, and how do I do ____

Previous Thread :: Next Thread 
Clayguy247 is not online. Clayguy247
Joined: 03 Sep 2008
Total Posts: 3394
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 is not online. 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
Clayguy247 is not online. Clayguy247
Joined: 03 Sep 2008
Total Posts: 3394
31 Jul 2013 01:55 AM
Thanks a ton, I really learned a lot through this
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image