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

What is wrong with this counting script?

Asked by 10 years ago

So I want the script to activate when someone says a number greater than 0. It should then count up, printing all of the lower numbers. For example, if I say "5", it should print this: 1 2 3 4 5

If I said 3, it should print this: 1 2 3

It isn't working at all, here is my code.

x=0

function onChatted(message, player)
    if string.lower(message) >= 0 then
        repeat
    x = x+1
    print(x)
    wait(0.1)
until x == (message)
x = 0

    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end) 

1 answer

Log in to vote
0
Answered by
iaz3 190
10 years ago

You are attempting to compare a number and a string.

There is no such thing as uppercase and lowercase numbers, you do not need to call STRING.lower

Also, you don't need the player argument since you don't do anything with it(unless you later plan to implement a message for the player to see the count)

You also don't need to have x as a global variable(no local, and also outside the function,unless you plan to have other code mess with it), and you should ALWAYS define variables local(local before the variable name), it is faster.

function onChatted(message, player)
    local x = 0
    if message >= 0 then
        repeat
            x = x + 1
            print(x)
            wait(0.1)
        until x == (message)
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end) 
Ad

Answer this question