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

Why is it printing nil instead of the value?

Asked by 5 years ago
Edited 5 years ago

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)
0
Thank you so so so so so so much! turquoise_monkeyman 32 — 5y
0
if you haven't noticed yet, you misspelled "answer" on line 8. nikki9dor 28 — 5y

1 answer

Log in to vote
0
Answered by
HDWC 53
5 years ago

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

Ad

Answer this question