Button telport script to spawnpoint block?
Im trying to figure out how to make a click telporter to telport to diffrent areas this is my script
01 | modelname = "teleporter1b" |
03 | function onTouched(part) |
04 | if part.Parent ~ = nil then |
05 | local h = part.Parent:findFirstChild( "Humanoid" ) |
07 | local teleportfrom = script.Parent.Enabled.Value |
08 | if teleportfrom~ = 0 then |
12 | local teleportto = script.Parent.Parent:findFirstChild(modelname) |
13 | if teleportto~ = nil then |
14 | local torso = h.Parent.Torso |
15 | local location = { teleportto.Position } |
18 | local x = location [ i ] .x |
19 | local y = location [ i ] .y |
20 | local z = location [ i ] .z |
22 | x = x + math.random(- 1 , 1 ) |
23 | z = z + math.random(- 1 , 1 ) |
24 | y = y + math.random( 2 , 3 ) |
26 | local cf = torso.CFrame |
31 | script.Parent.Enabled.Value = 0 |
32 | teleportto.Enabled.Value = 0 |
33 | torso.CFrame = CFrame.new(Vector 3. new(x,y,z), Vector 3. new(lx,ly,lz)) |
34 | script.Parent.Enabled.Value = 1 |
35 | teleportto.Enabled.Value = 1 |
37 | print ( "Could not find teleporter!" ) |
44 | script.Parent.Touched:connect(onTouched) |
46 | function getPlayer(humanoid) |
47 | local players = game.Players:children() |
49 | if players [ i ] .Character.Humanoid = = humanoid then return players [ i ] end |
56 | local human = part.Parent:findFirstChild( "Humanoid" ) |
57 | if (human = = nil ) then return end |
59 | local player = getPlayer(human) |
61 | if (player = = nil ) then return end |
65 | game.Lighting.NAME:clone().Parent = player.Backpack |
70 | script.Parent.Touched:connect(onTouch) |