Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is it printing nil instead of the value?

I want to make a script where whenever the person says a number something happens but when I started a problem started occurring please help It prints nill when i say it. I think it is something to do with my answer my script is :

 game.Players.PlayerAdded:Connect(function(player)
math.randomseed(tick())
for _ = 1, 1 do
local answer = (math.random(100))
end
player.Chatted:Connect(function(message)
if message == "red" then
print(awnswer)
end
end)
end)

2 comments

0

Thank you so so so so so so much!

0

if you haven't noticed yet, you misspelled "answer" on line 8.

1 answer

✓ Accepted answer

Youre doing local wrong. Get rid of your for loop. Instead do:

 game.Players.PlayerAdded:Connect(function(player)
 math.randomseed(tick())
 local answer = math.random(100)
 player.Chatted:Connect(function(message)player.Chatted:Connect(function(message)
		if message == "red" then
			print(answer)
		end
	end)
end)

hope this helps

btw output should just be a random number

This discussion is preserved as it was. New answers, comments, and votes are closed.