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

Else not functioning correctly?

Here's the script

                   local Selector = math.random(1)
                   local Player = game.Players.LocalPlayer
                   local Rarities = math.random(70,75)
                   Common = 70
                   CommonWorth = 1000
                   local A = math.random(70,100)--Common

                  if Selector == 1 then
                  if Rarities ~= Common or A then
                  print("No luck! Try again.")
                  else
                  if Rarities == Common or A then
                 print("Common")	
                 Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value + CommonWorth

         end
        end
       end

The problem is it always says in the output No luck! Try again. Any Ideas??

3 answers

function select()
  local Selector = math.random(1,2) -- you put only 1 possible number to be chosen
  local Player = game.Players.LocalPlayer
  local Rarities = math.random(70,75)
  local commonRarity = 70
  local common2Rarity = 100
  local commonWorth = 1 --- change this

  local pickCommon = math.random(70,100) 

  if Selector == 1 then
    if Rarities ~= commonRarity or common2Rarity then
      print("No luck! Try again")
    elseif Rarities == commonRarity or common2Rarity then
      print("Common")
    end
    Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value + commonWorth -- I chose worth because that adds worth of the common
  end 
end


select()

Let me know if this works, I didn't have the opportunity to test it.

5 comments

0

Lol I don't mean common2 is a rarity, I forgot to add beside it The worth... I am sorry, lol Anyways. let me test it

0

Weird, It still says No luck! Try again

0

Try it multiple times

0

I'd say at least 10 times

0

1 problem, It still adds even when its not supposed to, like selector = 1 and rarities = 4

With this code, Selector is going to be 0 or 1. In order to get what you want, you need to set the parameter of math.random to the biggest number you want to be possible.

local Selector = math.random(1000) -- Always going to be between 1 and 1000.

Additionally, setting a parameter before that will allow you to set the smallest possible number.

local Selector = math.random(100,1000) -- Always going to be between 100 and 1000.

If the minimum number is left out, it will default to 1. Hope this helps, and make sure to accept my answer if it does!

1 comment

0

Not what I wanted.. But thanks!

###Your problem lies in lines 9 and 12. You’re checking if Rarities is not equal to Common, but A with no context.

if Rarities ~= Common or A then

###You need to specify what A is. Are you checking if the Value of a NumberValue is equal to A? Are you checking if it’s the Transprency of a BasePart? You have to be specific.

-- Line 9
if Rarities ~= Common or Rarities ~= A then

-- Line 12
if Rarities == Common or Rarities == A then

1 comment

0

1 problem it sometimes work and sometimes it doesnt

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