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

How would you make it to where? [closed]

Asked by
IcyEvil 260 Moderation Voter
10 years ago

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)

Locked by BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
1
Answered by 10 years ago

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!

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! IcyEvil 260 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

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)
Log in to vote
-3
Answered by 10 years ago
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)
0
No... That would teleport them to a certain position, I'm wanting a random position in a given space. IcyEvil 260 — 10y
0
Wiki EzraNehemiah_TF2 3552 — 10y