Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to do Random Teleportation?

Asked by 10 years ago

So, I am trying to make it so that players teleport randomly to the location of different bricks on my map. I have no idea on how to use random numbers with this, or if that has any correlation with what I am trying to do. What do I have to tweak to make this teleport them to random blocks?

function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
t = h.Parent.Torso
t.CFrame = CFrame.new(script.Parent.Parent.Part1.Position)
end
end

script.Parent.Touched:connect(onTouched)

Thank you for your help, -Samson554

2 answers

Log in to vote
1
Answered by 10 years ago
local RandomParts = {game.Workspace.Part1, game.Workspace.Part2, game.Workspace.Part3} --This is a table, It consists of all your parts that 1 of can be selected to be teleported to.

function OnTouched(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then --Just a simple check to make sure that the hit is a player.
Hit.Parent:MoveTo(RandomParts[math.random(1,#RandomParts)].Position)
--If you want the Player to be teleported just above the part do the following after ].Positon, + Vector3.new(0, 5, 0)
end
end

script.Parent.Touched:connect(OnTouched)
0
Oh! I knew I had to use the math.random piece in there somewhere. Thanks! Samson554 25 — 10y
0
Np! xImmortalChaos 565 — 10y
Ad
Log in to vote
-6
Answered by 10 years ago

Not something I can solve, but you probably need to use math.random

3
Do not contribute if you have nothing constructive to contribute. BlueTaslem 18071 — 10y

Answer this question