Code not working

wait(0.1)
math.random (print ("hi"))

if  print("hi") then
	script.Parent.Brightness = 5
	
else
	
	script.Parent.Brightness 0
end

script not working, help?

2 Likes

ok so, math.random only works with numbers, while you passed a print statement. Try to change line 2 to math.random(0,2) instead

2 Likes

try

words = {"lol", "hi"}-- you can put as much words as possible! make sure you add a comma
if  print(words[math.random(1 , #words)]) == "hi" then 
 script.Parent.Brightness = 5
 
else
 
 script.Parent.Brightness 0
end

On line 2, it looks like you tried to use a print function inside of a math.random operation. Math.random only works with numbers, and you tried to pass a function so you should pass a number instead.
For example:

randominteger = math.random(integer1,integer2)

Hope this helps!

1 Like

mayeb do something like

wait(0.1)
local randomNum = math.random()

if randomNum then
    script.Parent.Brightness = 5
else
script.Parent.Brightness = 0
end

im not a scripter don't blame me

Although your code looks good, it’s missing 1 thing:

You’re checking if the words math.random function will work, when you should do this instead:

local Words = {"lol,", "hi"}

local RandomString = Words[math.random(1, #Words)]

if RandomString == "hi" then
    print("hi")
    script.Parent.Brightness = 5
else
    script.Parent.Brightness = 0
end
1 Like

why would i do that???

do

wait(0.1)
local RandomNumber = math.random(1,2)

if  RandomNumber == 1 then
	script.Parent.Brightness = 5
	
else
	
	script.Parent.Brightness 0
end
1 Like

It’s just a better approach & organized way of doing it, idk if using a conditional statement for a print() would work

It wouldn’t because print doesn’t return a value.

1 Like

Yeah, it’s not going to work. Your code is not structurally valid, as will have been pointed out to you by your IDE if you are coding in Roblox Studio.

Your question is impossible to answer because I have no idea what your code is meant to do. What exactly do you want it to achieve?

1 Like