Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with randomising?

Asked by 10 years ago

How can I get a random number between 1 and 10, and add it to a string. for example

I get 7

'You caught a 7lb fish!'

another example:

You caught a 2lb fish!'

please help

0
I'll get to work on an answer. Mowblow 117 — 10y

3 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

Use math.random.

lbs=math.random(1,10)

0
And this was downvoted because.... 0_o M39a9am3R 3210 — 10y
0
Neutralized, some people just find it funny to down-vote members with ^rep ImageLabel 1541 — 9y
0
Probably downvoted because of lack of information. If your answer isn't well written and just looks generally sloppy, that's enough of a reason to downvote over a better presented answer. Unclear 1776 — 9y
0
Yeah, but you got to admit, this is old content. I didn't give much explanation with my scripts when I was starting out and I ended up getting my butt kicked when harder questions started coming out. So I of course had to give better explanation with my scripts. M39a9am3R 3210 — 9y
Ad
Log in to vote
0
Answered by
Mowblow 117
10 years ago

A way to do this is using

 local g = math.random(1,10)

this creates a random number between one, and ten.

To put this into a string, you would do string value.

local stringvalue = script.Parent.Pounds.Value -- Referencing the value.
local f = tostring("You have caught a"..g.."lb. fish!") -- This combines g, our math.random, and the string.
stringvalue = f -- Makes the value equal to the tostring function.
0
Hope this helps! Mowblow 117 — 10y
Log in to vote
0
Answered by 9 years ago
lbs = math.random(0, 10)

if lbs > 5 then
    print("You got a big fish ! :)")
else
    print("You got a little fish ! :(")
end

or you can also do this:

lbs = math.random(0, 10)

print("You caught a "..lbs.."lb".."fish !")

Answer this question