I made a script that teleports you to a certain brick depending on a number generated by math.random
. However, this particular script only seems to transport me to the destination denoted by number 3. Here is the script.
01 | function transport() |
02 | math.randomseed(tick()) |
03 | local num = math.random( 1 , 4 ) |
04 | wait() |
05 | if num = = 1 then |
06 | script.Parent.Parent.Torso.CFrame = game.Workspace.planetbeam.CFrame + Vector 3. new( 0 , 5 , 0 ) |
07 | elseif num = = 2 then |
08 | script.Parent.Parent.Torso.CFrame = game.Workspace.bridgebeam.CFrame + Vector 3. new( 0 , 5 , 0 ) |
09 | elseif num = = 3 then |
10 | script.Parent.Parent.Torso.CFrame = game.Workspace.brigbeam.CFrame + Vector 3. new( 0 , 5 , 0 ) |
11 | elseif num = = 4 then |
12 | script.Parent.Parent.Torso.CFrame = game.Workspace.medbeam.CFrame + Vector 3. new( 0 , 5 , 0 ) |
13 | end |
14 | script.Parent.Handle.Sound:play() |
15 | wait( 2.04 ) |
16 | script.Parent:Destroy() |
17 | end |
18 | end |
19 |
20 | script.Parent.Activated:connect(transport) |
Can anybody help?
I see 2 errors in your script. First of all, CFrame + Vector3 doesn't work, so you'd have to do CFrame * CFrame, how would you do that? Here:
1 | local CFrame 1 = CFrame.new( 0 , 0 , 0 ) |
2 | local CFrame 2 = CFrame.new( 0 , 50 , 25 ) |
3 | local CFrame 3 = CFrame 1 * CFrame 2 |
So, to fix off your script, it would be:
01 | function transport() |
02 | math.randomseed(tick()) |
03 | local num = math.random( 1 , 4 ) |
04 | wait() |
05 | if num = = 1 then |
06 | script.Parent.Parent.Torso.CFrame = game.Workspace.planetbeam.CFrame * CFrame.new(Vector 3. new( 0 , 5 , 0 )) |
07 | elseif num = = 2 then |
08 | script.Parent.Parent.Torso.CFrame = game.Workspace.bridgebeam.CFrame * CFrame.new(Vector 3. new( 0 , 5 , 0 )) |
09 | elseif num = = 3 then |
10 | script.Parent.Parent.Torso.CFrame = game.Workspace.brigbeam.CFrame * CFrame.new( Vector 3. new( 0 , 5 , 0 )) |
11 | elseif num = = 4 then |
12 | script.Parent.Parent.Torso.CFrame = game.Workspace.medbeam.CFrame * CFrame.new(Vector 3. new( 0 , 5 , 0 )) |
13 | end |
14 | script.Parent.Handle.Sound:play() |
15 | wait( 2.04 ) |
16 | script.Parent:Destroy() |
17 | end |
18 | end |
19 |
20 | script.Parent.Activated:connect(transport) |
Hope this helped :)