I finished the beginning of it and too see if it works, I press play and press f, which is the input i've chosen to change the math, and nothing pops up in the output. I'm somewhat of a beginner, so please give some feedback ill understand!
01 | local chance = math.random() |
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | UserInputService.InputBegan:Connect( function (input, event) |
04 | if input.KeyCode = = Enum.KeyCode.F then |
05 | if chance = . 1 then |
06 | print ( 'lol its a one' ) |
07 | end |
08 | if chance = . 2 then |
09 | print ( 'oof its a two' ) |
10 | end |
11 | if chance = . 3 then |
12 | print ( 'yeet its a three' ) |
13 | end |
14 | if chance = . 4 then |
15 | print ( 'what a beaner its a four' ) |
yes i understand it goes through 0-1 but i don't think thats the problem here.
You made a great attempt on your code. To point out some issues with it, math.random() returns a decimal number between 0 and 1. It will most likely never be a clean rational 0.1, but more so a 0.1214101241. Instead, you could set your bounds to be between 1 and 6, and in doing so it will only choose whole numbers. For your if statements, you'd want to use elseif's since you're comparing one outcome, which is the outcome of your die (singular for dice). Lastly, the comparison operator is ==
, where you only had =
. One equal sign is for an expression, to define something. Any questions, just comment!
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | UserInputService.InputBegan:Connect( function (input, event) |
03 | if input.KeyCode = = Enum.KeyCode.F then |
04 | local chance = math.random( 1 , 6 ) -- So it can be a different number each time they press F |
05 | if chance = = 1 then |
06 | print ( 'lol its a one' ) |
07 | elseif chance = = 2 then |
08 | print ( 'oof its a two' ) |
09 | elseif chance = = 3 then |
10 | print ( 'yeet its a three' ) |
11 | elseif chance = = 4 then |
12 | print ( 'what a beaner its a four' ) |
13 | elseif chance = = 5 then |
14 | print ( 'lol noob u got a five hahaha' ) |
15 | elseif chance = = 6 then |
16 | print ( 'f in chat you just won the game rolling a six!' ) |
17 | end |
18 | end |
19 | end ) |
The error was line 1, its hard to explain but u have to put the numbers inbetween the math.random brackets thing. Try this script
01 | local chance = math.random( 1 , 6 ) |
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | UserInputService.InputBegan:Connect( function (input, event) |
04 | if input.KeyCode = = Enum.KeyCode.F then |
05 | if chance = 1 then |
06 | print ( 'lol its a one' ) |
07 | end |
08 | if chance = 2 then |
09 | print ( 'oof its a two' ) |
10 | end |
11 | if chance = 3 then |
12 | print ( 'yeet its a three' ) |
13 | end |
14 | if chance = 4 then |
15 | print ( 'what a beaner its a four' ) |
Pretty close but there is a few errors.
math.random needs a set of numbers in it otherwise it will automatically pick a number from 0-1 and can be unreliable.
1 | local chance = math.random( 1 , 6 ) |
This will make the math.random choose a number from one to six.
1 | if chance = 1 then |
When trying to check a number or string from a variable use == this will check if chance is the same number as 1. Using one equals will be telling the script to change the chance to 1 but it wont work.
Example:
1 | if chance = = 1 then |
Working Script:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 |
03 | UserInputService.InputBegan:Connect( function (input, event) |
04 | if input.KeyCode = = Enum.KeyCode.F then |
05 |
06 | local chance = math.random( 1 , 6 ) |
07 |
08 | if chance = = 1 then |
09 | print ( 'lol its a one' ) |
10 | end |
11 |
12 | if chance = = 2 then |
13 | print ( 'oof its a two' ) |
14 | end |
15 |