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

[SOLVED] math.random(number) Get Value by a variable?

so i have this script which Teleports people to diffrent places on the map when the game starts im trying to make it so i have a math.random(8) and if its a certain number you get teleported to a diffrent place on the map. In conclusion how do you store math.random data in variables?heres the code. But for some reason it doesnt run the code inside the Get Players Code. It doesnt even print Works

Players = game:GetService("Players")

for i, player in pairs(Players:GetPlayers()) do

Number = math.random(1,8)

if Number == 1 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-30.13, 0.5, 33.825))

print("Works")

end

if Number == 2 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(99.37, 0.5, 32.825))

print("Works")

end

if Number == 3 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(97.37, 0.5, 164.325))

print("Works")

end

if Number == 4 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-32.63, 0.5, 169.825))

print("Works")

end

if Number == 5 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-29.63, 0.5, 93.325))

print("Works")

end

if Number == 6 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(38.87, 0.5, 36.825))

print("Works")

end

if Number == 7 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(38.87, 0.5, 36.825))

print("Works")

end

if Number == 8 then

game.Workspace[player.Name].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(95.37, 0.5, 101.825))

print("Works")

end

end

3 comments

0

Why not just make parts and teleport the player to the specified part? This way you dont have to do a bunch of variables and you can have cleaner code.

0

Wait thats not it i want a bunch of players teleport to random places on the map its a serverside code

0

Basically if i do local Number = math.random(8) print(Number) thats what i want to do

1 answer

✓ Accepted answer
local RandomNumber = math.Random(1, 8)  

4 comments

0

ill try

0

I Swear i feel Stuipid AF right now

0

omegalul

0

I Legit spent like 4 hrs trying to fix this Omegalul

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