generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How do I make something have a 25% chance of happening?

Previous Thread :: Next Thread 
Bannerlord is not online. Bannerlord
Joined: 10 Oct 2014
Total Posts: 89
19 Oct 2014 08:16 AM
Using this for a tycoon I am making which will feature an R%D room. You invest into a button and you have a 50% chance to get double your money, 5% chance to lose the money, 20% chance to get the money back, 20% chance to get triple your money and 5% chance to quadruple it.

But how would I do this? I know this isn't the place to ask for scripts, but I was hoping someone would be generous enough to at least give me the segment of script that does the 25% bit for me to edit.
Report Abuse
Bannerlord is not online. Bannerlord
Joined: 10 Oct 2014
Total Posts: 89
19 Oct 2014 08:17 AM
R&D not R%D.
Report Abuse
Barcado is not online. Barcado
Joined: 04 Oct 2014
Total Posts: 1278
19 Oct 2014 08:24 AM
local rand = math.random(1, 4) --only handles a 25% situation
if rand == 1 then
--junk
elseif rand == 2 then
--junk
end
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
19 Oct 2014 08:31 AM
local chance = math.random(1, 100)
if chance <= 50 then
-- double money
elseif chance <= 55 then
-- lose money
elseif chance <= 75 then
-- get money back
elseif chance <= 95 then
-- triple money
elseif chance <= 100 then
-- quadruple money
end

~The herp lerped a derp~
Report Abuse
Bannerlord is not online. Bannerlord
Joined: 10 Oct 2014
Total Posts: 89
19 Oct 2014 08:33 AM
Thanks a lot. If I do this:

local chance = math.random(1, 100)

then use <= and >= (or =< and =>, whichever one it is), could I still get 5% and other things?

Does <= (or =<) work like this as well?:

if chance> and <=5 then
--quadruple money

If not is there a way to have it be in-between them?
Report Abuse
Bannerlord is not online. Bannerlord
Joined: 10 Oct 2014
Total Posts: 89
19 Oct 2014 08:34 AM
Ah, thanks!
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
19 Oct 2014 08:50 AM
Or just make it simple and do this:

local integer = math.random(1,4)
if integer == 3 then
--code
end
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
19 Oct 2014 08:54 AM
You could, but you know. Collective values.
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
19 Oct 2014 09:03 AM
I have absolutely no idea what on this datamodel(http://roblox.com/asset?id=23027323) you are talking about.
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
19 Oct 2014 09:07 AM
If you didn't get the joke, the datamodel I linked was earth.
Report Abuse
Bannerlord is not online. Bannerlord
Joined: 10 Oct 2014
Total Posts: 89
19 Oct 2014 09:13 AM
Thanks everyone. Finished script for anyone interested:

price = script.Parent.Price

wait(1)

oldname = script.Parent.Parent.Name
owner = script.Parent.Parent.Parent.Owner
local debounce = 0

function onTouched(hit)
if debounce == 0 then
debounce = 1
check = hit.Parent:FindFirstChild("Humanoid")

if check ~= nil then
if hit.Parent.Name == owner.Value then
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
local stats = user:FindFirstChild("leaderstats")

if stats ~= nil then
local money = stats:FindFirstChild("Money")
if money.Value > (price.Value - 1) then
local chance = math.random(1, 100)
if chance <= 50 then
money.Value = money.Value + (price.Value * 2)
script.Parent.Parent.Name = "Money doubled."
script.Parent.Parent.Parent.Purchased:Play()
wait(3)
script.Parent.Parent.Name = oldname
debounce = 0
elseif chance <= 55 then
money.Value = money.Value - price.Value
script.Parent.Parent.Name = "Money lost."
wait(3)
script.Parent.Parent.Name = oldname
debounce = 0
elseif chance <= 75 then
script.Parent.Parent.Name = "Money returned."
wait(3)
script.Parent.Parent.Name = oldname
debounce = 0
elseif chance <= 95 then
money.Value = money.Value + (price.Value * 3)
script.Parent.Parent.Name = "Money tripled!"
script.Parent.Parent.Parent.Purchased:Play()
wait(3)
script.Parent.Parent.Name = oldname
debounce = 0
elseif chance <= 100 then
money.Value = money.Value + (price.Value * 4)
script.Parent.Parent.Name = "Money QUADRUPLED!"
script.Parent.Parent.Parent.Purchased:Play()
wait(3)
script.Parent.Parent.Name = oldname
debounce = 0
end
end
end
end
end
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
xXScriptzXx is not online. xXScriptzXx
Joined: 13 Jan 2013
Total Posts: 4452
19 Oct 2014 09:27 AM
Math...
You need it for scripting, sorry.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image