maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 25 Nov 2013 04:27 PM |
I'm trying to make a model become a random color once someone touches it, but instead of the model becoming a different color, my head becomes a different color. When I've encountered this problem in the past, it was due to the fact that my local variable had used used outside its scope. The thing is, I use a for loop to do the GetChildren thing, and I'm not sure if that's local or not, and how to fix it so that either it's global, or to rearrange the script so that it works properly.
for i,v in pairs (script.Parent.Parent:GetChildren ()) do function OnTouch (v) local h = v.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = 0 wait(1) end v.BrickColor = BrickColor.new (math.random ()) v.Transparency = math.random (0,1) end v.Touched:connect (OnTouch) end
|
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 25 Nov 2013 04:38 PM |
| How come this forum always dies once I post asking for help, but is so vibrant while i'm giving it? |
|
|
| Report Abuse |
|
|
dmjoe
|
  |
| Joined: 01 May 2009 |
| Total Posts: 2387 |
|
|
| 25 Nov 2013 04:45 PM |
par = script.Parent.Parent:GetChildren() for x=1,#par do par[x].Touched:connect(function(hit) human = hit.Parent:findFirstChild("Humanoid") if human then human.Health = 0 wait(1) par[x].BrickColor = BrickColor.new (math.random ()) par[x].Transparency = math.random (0,1) end end)
Try this, not tested. |
|
|
| Report Abuse |
|
|
dmjoe
|
  |
| Joined: 01 May 2009 |
| Total Posts: 2387 |
|
| |
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 25 Nov 2013 04:58 PM |
No output, although I had to change the end a bit to make them match up. It only changes one of the bricks in the model, though.
par = script.Parent.Parent:GetChildren() for x=1,#par do par[x].Touched:connect(function(hit) human = hit.Parent:findFirstChild("Humanoid") if human then human.Health = 0 wait(1) par[x].BrickColor = BrickColor.new (math.random ()) par[x].Transparency = math.random (0,1) end end) end |
|
|
| Report Abuse |
|
|
dmjoe
|
  |
| Joined: 01 May 2009 |
| Total Posts: 2387 |
|
|
| 25 Nov 2013 05:06 PM |
| I don't think you can use an event inside a for loop like that, but I don't know an alternative. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 25 Nov 2013 09:43 PM |
I know this might sound really bad, but: define event, please.
Also, alternatives would be nice! Anyone think they have an answer? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Nov 2013 09:45 PM |
You could do anything in a for loop... But that, right there, is inefficient, do this
function OnTouch (v) local h = v.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = 0 wait(1) end v.BrickColor = BrickColor.new (math.random ()) v.Transparency = math.random (0,1) end
for i,v in pairs (script.Parent.Parent:GetChildren ()) do v.Touched:connect (OnTouch) end |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2013 09:49 PM |
No output, although I had to change the end a bit to make them match up. It only changes one of the bricks in the model, though.
par = script.Parent.Parent:GetChildren() for k, v in pairs(par) do v.Touched:connect(function(hit) human = hit.Parent:findFirstChild("Humanoid") if human then human.Health = 0 wait(1) v.BrickColor = BrickColor.new (Color3.new(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255)) v.Transparency = math.random (0,1) end end) end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Nov 2013 09:50 PM |
| v.BrickColor = BrickColor.Random()* |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Nov 2013 09:51 PM |
I hate ninja's And I hate flood check
Combine the two: w33w00 |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 26 Nov 2013 06:55 AM |
I really thought cntkillme's would work -I've seen him many times on this forum and he always gives good advice- but I found that chickenman's script worked.
There's just one problem: how do I get it so that all the bricks change to a random, yet uniform color?
I got some of them to be a uniform color, but some aren't:
par = script.Parent.Parent:GetChildren() randombrick = script.Parent for k, v in pairs(par) do v.Touched:connect(function(hit) human = hit.Parent:findFirstChild("Humanoid") if human then human.Health = 0 wait(1)
randombrick.BrickColor = BrickColor.new (Color3.new(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255)) v.BrickColor = randombrick.BrickColor
randombrick.Transparency = math.random (0.4,.8) v.Transparency = randombrick.Transparency end end) end |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2013 07:41 AM |
randombrick.Transparency = math.random (0.4,.8) (0.4,.8)is it exist? |
|
|
| Report Abuse |
|
|
| |
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 26 Nov 2013 03:28 PM |
Due to how it looks, I omitted it from the script, but I'll store that away for future use.
How do I get the bricks to have uniform, yet randomly chosen, BrickColor |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 26 Nov 2013 04:23 PM |
| I could've sworn my method would work, but now only about half of them keep the uniform color. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 26 Nov 2013 05:46 PM |
| Going through a dry-spell, I see. I'm very close to finishing this game! Come on! |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
| |
|
|
| 26 Nov 2013 08:36 PM |
Idk how you would script this and it would probobly take a long time...
But anyways: Make one brick in model named BaseForChangeColor change color randomly. Then put a script in the rest of the bricks that checks the color of the BaseForChangeColor brick and change accordingly. But one thing, with my level of scripting i am thinking that it would be something like this: If parent.parent.BaseForChangeColor.brickcolor == 1,1,1 then parent.brickcolor = 1,1,1 elseIf parent.parent.BaseForChangeColor.brickcolor == 2,1,1 then parent.brickcolor = 2,1,1 etc.etc. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 27 Nov 2013 09:27 AM |
| Haha, clever idea. Not the correct format at all, but lovely idea. I'll be posting how to do this properly as a thanks! |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 27 Nov 2013 04:57 PM |
It's poorly inefficient, but I ended up assigning all the bricks names, and doing it manually.
I still used the last replier's idea, so here's how I did it:
randombrick.Value = BrickColor.new (Color3.new(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255)) -- This is that outside value part1.BrickColor = randombrick.Value part2.BrickColor = randombrick.Value part3.BrickColor = randombrick.Value part4.BrickColor = randombrick.Value |
|
|
| Report Abuse |
|
|