|
| 23 Jul 2012 09:28 PM |
| I am trying to make it so that a teleporter randomly sends you to one of 7 bricks (positions)... would i use math.random()? If not what would i use?(i know the code just not the random brick(position) part) |
|
|
| Report Abuse |
|
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 23 Jul 2012 09:40 PM |
If the parts are all in the same model, do something like this. This probably won't work, but you get the idea.
Player:MoveTo(Model:GetChildren(math.random(#Model:GetChildren())) |
|
|
| Report Abuse |
|
|
| |
|
|
| 23 Jul 2012 09:43 PM |
Player.Character:MoveTo(Model:GetChildren()[math.random(1,#Model:GetChildren())].Position + Vector3.new(0,6,0))
|
|
|
| Report Abuse |
|
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 23 Jul 2012 09:45 PM |
Little mistake
Player:MoveTo(Model:GetChildren[math.random(#Model:GetChildren())]) |
|
|
| Report Abuse |
|
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 23 Jul 2012 09:46 PM |
I need to proof-read.
Player:MoveTo(Model:GetChildren()[math.random(#Model:GetChildren())]) |
|
|
| Report Abuse |
|
|
| |
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 23 Jul 2012 09:48 PM |
| Thanks for pointing out my mistake. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 09:52 PM |
Here's where I'm at.....
Model = game.Workspace.SpawnBricks
function touched(hit) local Player = hit.Parent if Player ~= nil then Player:MoveTo(Model:GetChildren(math.random(#Model:GetChildren()))) end end
script.Parent.Touched:connect(touched)
Output:22:50:45 - Unable to cast Array to Vector3 22:50:45 - Script "Workspace.Spawn House.Spawn?.Head.Script", Line 6 22:50:45 - stack end 22:50:45 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 09:53 PM |
| herp i neglected to look at the recent post ignore that last post.... |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 23 Jul 2012 10:01 PM |
what about this:
Model = game.Workspace.SpawnBricks
function touched(hit) local Player = hit.Parent if Player ~= nil then Player.Character:MoveTo(Model:GetChildren()[math.random(#Model:GetChildren())]) end end
script.Parent.Touched:connect(touched)
Output:22:59:34 - Character is not a valid member of Model 22:59:34 - Script "Workspace.Spawn House.Spawn?.Head.Script", Line 6 22:59:34 - stack end 22:59:34 - Disconnected event because of exception
Is player suppose to be the Player from 'Players' ?
|
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 10:02 PM |
| In that script's case, erase the .Character. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 10:08 PM |
Removing the '.Character' gave me this output:
23:06:34 - Unable to cast Instance to Vector3 23:06:34 - Script "Workspace.Spawn House.Spawn?.Head.Script", Line 6 23:06:34 - stack end 23:06:34 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 10:17 PM |
| doesnt there need to be three(X,Y,Z) things in the :MoveTo() |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 10:41 PM |
Player.Character:MoveTo(Model:GetChildren()[math.random(#Model:GetChildren())])
Ugg dang it, I think my brain just rotted trying to convert this to something else. Umm.
Player.Character:MoveTo(Model[math.random(#Model:GetChildren())].Position)
Idk, my brain just farted. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 10:49 PM |
In this i can't use '.Character' so i changed it to this:
Model = game.Workspace.SpawnBricks
function touched(hit) local Player = hit.Parent if Player ~= nil then Player:MoveTo(Model[math.random(#Model:GetChildren())].Position) end end
script.Parent.Touched:connect(touched)
Output: 23:47:11 - 6 is not a valid member of Model 23:47:11 - Script "Workspace.Spawn House.Spawn?.Head.Script", Line 6 23:47:11 - stack end 23:47:11 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
| |
|
|
| 24 Jul 2012 12:15 PM |
It's not that complicated...
Model = game.Workspace.SpawnBricks enabled = true script.Parent.Touched:connect(function(hit) local player = Game.Players:GetPlayerFromCharacter(hit.Parent) if player and enabled then Player.Character:MoveTo(Model:GetChildren()[math.random(1,#Model:GetChildren())].Position + Vector3.new(0,6,0)) end end) |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2012 01:45 PM |
| thanks man it works! but on line 6 you capitolized the 'p' in player... lol |
|
|
| Report Abuse |
|
|