Ok. I tried to make a script where there's a math.random that gives you a certain value if you get a certain number.
local Backpack = game.Players.LocalPlayer:WaitForChild("Backpack") local playerquirk = Backpack:WaitForChild("Quirk") local quirk = math.random(1,10) if playerquirk.Value == "None" then game.Players.LocalPlayer.PlayerGui.GiveQuirk.PageOne.Quirk.TextButton.MouseButton1Down:Connect(function() if quirk == 1 then playerquirk.Value = "WarpGate" elseif quirk == 2 then playerquirk.Value = "Invisibility" elseif quirk == 3 then playerquirk.Value = "Invisibility" elseif quirk == 4 then playerquirk.Value = "HHHC" elseif quirk == 4 then playerquirk.Value = "Erasure" elseif quirk == 5 then playerquirk.Value = "Invisibility" elseif quirk == 6 then playerquirk.Value = "WarpGate" elseif quirk == 7 then playerquirk.Value = "HHHC" elseif quirk == 8 then playerquirk.Value = "Erasure" elseif quirk == 9 then playerquirk.Value = "Invisibility" elseif quirk == 10 then playerquirk.Value = "WarpGate" end script.Parent.Visible = false script.Parent.Parent.Text = playerquirk.Value wait(1.5) game.Players.LocalPlayer.PlayerGui.GiveQuirk.PageOne.Visible = false game.Players.LocalPlayer.PlayerGui.GiveQuirk.PageTwo.Visible = false game.Players.LocalPlayer.Character.Humanoid.Health = 0 end) end
NOT WORKING THOUGH! Help?
I've got a much more efficient way for doing what you're trying to do.
local Backpack = game.Players.LocalPlayer:WaitForChild("Backpack") local playerquirk = Backpack:WaitForChild("Quirk") if playerquirk.Value == "None" then game.Players.LocalPlayer.PlayerGui.GiveQuirk.PageOne.Quirk.TextButton.MouseButton1Down:Connect(function() local quirktable = { "Invisibility", "Invisibility", "Invisibility", "Invisibility", "WarpGate", "WarpGate", "WarpGate", "HHHC", "HHHC", "Erasure", "Erasure" } quirkchosen = quirktable[math.random(#quirktable)] playerquirk.Value = quirkchosen --whatever other code needed below
Alright, lets go through it!
local quirktable = { "Invisibility", "Invisibility", "Invisibility", "Invisibility", "WarpGate", "WarpGate", "WarpGate", "HHHC", "HHHC", "Erasure", "Erasure" }
This table named 'quirktable' contains a list of the quirks so that
quirkchosen = quirktable[math.random(#quirktable)]
Can get a random item from 'quirktable' and set it as the variable 'playerquirk', as seen in the last line of my code:
playerquirk.Value = quirkchosen
Hope I helped!
Computers cant always make random numbers, they always go off of a Puesdo which means its a pattern of numbers. So in lua there's something called Math.randomseed() which generates a new Puesdo depending on the number you put in. So if you do Math.randomseed(tick()) there will always be a random number due to tick() being changed every second. Also as well the first number in math.random is always the same number. To fix this issue write these 2 lines on the top of every script that uses math.random!
math.randomseed(tick()) --to generate a new puesdo math.random() -- to remove the first number that is always then same --Write the rest of your script