zaniac10Join Date: 2009-08-18 Post Count: 10000 |
for _,v in next, boxes do
local wear = math.random(1,1000)
local num = math.random(1,1000)
local b = v
if b.Name:sub(1,12) == "RandomNumber" then
if wear <= 200 then
b.Wear.Value = "Factory New"
elseif wear 200 then
b.Wear.Value = "Minimal Wear"
b.Cash.Value = b.Cash.Value * .8
elseif wear 400 then
b.Wear.Value = "Field-Tested"
b.Cash.Value = b.Cash.Value * .6
elseif wear 600 then
b.Wear.Value = "Well-Worn"
b.Cash.Value = b.Cash.Value * .4
elseif wear 800 then
b.Wear.Value = "Battle-Scarred"
b.Cash.Value = b.Cash.Value * .2
end
b.Cash.Value = math.floor(b.Cash.Value+.5)
end
end
end
basically cs go stuff where the higher the wear on the item the less it's worth, but it keeps on making all of the cash values 0... anyone know why?
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
bump
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
kiko
|
|
|
local wear = math.random(1,1000)
local num = math.random(1,1000)
using two random functions and comparing them will not work because of how lua's pseudo-random function works. It generates a random number from a random seed (usually tick()) that stays the same if you use it twice at the same time. Look up math.randomseed on the roblox wiki. That might explain it better than I have, as I'm just giving you the general idea of it.
|
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Uh, no. He'll more than likely get 2 different numbers. |
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
so does anyone know the solution?
|
|
KodranJoin Date: 2013-08-15 Post Count: 5330 |
What does b.Cash.Value start as? |
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
0, but code above this(this is key, setting the cash values happens before this set of code) sets it to a certain amount
|
|
KodranJoin Date: 2013-08-15 Post Count: 5330 |
do print(b.Cash.Value) a bunch of times throughout the code to see when/if it changes and what it changes to at each stage. |
|
|
"do print(b.Cash.Value) a bunch of times throughout the code to see when/if it changes and what it changes to at each stage."
Or, use the Debugger because it's more fun, has more helpful features and diagnostics, and so forth.
|
|
KodranJoin Date: 2013-08-15 Post Count: 5330 |
Haven't done much roblox scripting in the last while, I didn't even know that was a feature when did they add it? |
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
Entire update function:
http://pastebin.com/eb19cxUG
|
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
NumberValue.
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
Please, you guys... I'm desperate.
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
Anyone?
|
|
zaniac10Join Date: 2009-08-18 Post Count: 10000 |
Can't the most renowned scripting subforum resolve this?
|
|
KodranJoin Date: 2013-08-15 Post Count: 5330 |
elseif num > 232 then
b.BackgroundColor3 = milspec
b.Cash.Value = math.random(3,19)/100
end
There's a 76.8% chance that this changes cash.Value to somewhere between 0.03 to 0.19
Then you're multiplying it by .2, .4, .6, or .8 making it at most 0.152 which rounds down to 0. |
|
RockeniteJoin Date: 2011-12-20 Post Count: 1444 |
Can't the most renowned scripting subforum resolve this?
Can't the only scripting subforum resolve this?*
~~~Da siggy is OP~~~ |
|
KodranJoin Date: 2013-08-15 Post Count: 5330 |
I mean, he's not wrong... |
|
OslayisJoin Date: 2016-02-24 Post Count: 73 |
'math.floor(b.Cash.Value+.05)' is your problem. Math.floor rounds it to the nearest integer. In that case, it's 0. Integers don't normally include decimals. So, it'd be best if you did this; math.floor(((b.Cash.Value+.05)*100))/100
Or at least something like that.
-DevB
|
|
KodranJoin Date: 2013-08-15 Post Count: 5330 |
@Dev
"Integers don't normally include decimals"
This sentence gave me cancer.
Anyways, he is trying to round to the nearest integer, that's the point of his script. His problem is that he has a logic error I previously pointed out making it likely that the number will always round to 0. |
|
|
OslayisJoin Date: 2016-02-24 Post Count: 73 |
@Kodran
No need to bash on me for trying to help. Just a tip too, in other forums when you want to help someone fix a bug, try to assist them by making their variables local. The game will have less lag, even if it is just the slightest amount.
|
|