|
| 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 |
|
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 19 Oct 2014 08:54 AM |
| You could, but you know. Collective values. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 19 Oct 2014 09:27 AM |
Math... You need it for scripting, sorry. |
|
|
| Report Abuse |
|
|