Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you make it to where?

How would you make it to where when you touch a brick it randomly teleports you to a random region in an enclosed space, as in I put down 4 bricks all around the baseplate, I can then be teleported randomly inside that space but not outside of said space.

Any Help on this subject, and or an Example?

(THIS IS NOT ASKING FOR YOU TO SCRIPT FOR ME, I AM ASKING FOR AN EXAMPLE BECAUSE I HAVE NO CLUE ON HOW TO DO THIS)

3 answers

✓ Accepted answer

LordDragonZord, your answer is really unhelpful. Here's a real, constructive answer.

This can be achieved using math.random. First, we'll identify the length and breadth of the given area (we'll name the area Baseplate as an example). Then, we'll tell math.random to choose any number in between the size of that area. Script:

local area = game.Workspace.Baseplate

local x = area.Size.X
local z = area.Size.Z

local maxX = area.Position.X / (x / 2)
local minX = area.Position.X * (x / 2)
local maxZ = area.Position.Z / (z / 2)
local minZ = area.Position.Z * (z / 2)

game.Workspace.Player1.Torso.CFrame = CFrame.new(math.random(minX, maxX), area.Position.Y + 5, math.random(minZ, maxZ))

-- The part in the middle that says "area.Position.Y + 3) means that the player will be teleported 3 studs ABOVE the area, so that they don't get stuck.

If this doesn't work, please tell me and I'll try to fix it!

1 comment

0

I am wanting it for anyone who touches said Brick, Ill Configure this to do my work, Ill Tell you if I have problems!

Use math.random for CFrame so it would look like this:

script.Parent.Touched:connect(function(char)
local h = char.Parent.Humanoid
if h then
h.Parent.Torso.CFrame = CFrame.new(math.random(x,x), 0, math.random(z,z)) -- Change the x and z between two values. I recommend leaving y to 0. So for example, x can be between -4 and 2.
end)
script.Parent.Touched:connect(function(char)
local h = char.Parent.Humanoid
if h then
h.Parent.Torso.CFrame = CFrame.new(0,0,0)--Position
end)

2 comments

0

No... That would teleport them to a certain position, I'm wanting a random position in a given space.

0

Wiki

This discussion is preserved as it was. New answers, comments, and votes are closed.