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

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

Asked by 5 years ago
Edited 5 years ago

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
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. Mr_Unlucky 1085 — 5y
0
Wait thats not it i want a bunch of players teleport to random places on the map its a serverside code Oskar2266001 3 — 5y
0
Basically if i do local Number = math.random(8) print(Number) thats what i want to do Oskar2266001 3 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
local RandomNumber = math.Random(1, 8)  
0
ill try Oskar2266001 3 — 5y
0
I Swear i feel Stuipid AF right now Oskar2266001 3 — 5y
0
omegalul SuperSamyGamer 316 — 5y
0
I Legit spent like 4 hrs trying to fix this Omegalul Oskar2266001 3 — 5y
Ad

Answer this question