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

How do I convert a string to an integer? [solved]

Asked by
gitrog 326 Moderation Voter
7 years ago
Edited by M39a9am3R 7 years ago

I wrote a pay command, and it seems to work fine, except for this error

11:02:48.400 - ServerScriptService.PayCommand:10: attempt to compare string with number

How do I turn the string to an integer?

--Gitrog's Pay Command
--Retrieves a money tool from the specified location, and when that tool is used it gives that much money.
--Script requires a money leaderstat

local location = game.ServerStorage.SpawnerStorage --Where you are storing MoneyTool

function onChatted(message, player)
    if message:sub(1,5) == "/pay " then
        local money = message:sub(6)
        if player.leaderstats.Money.Value >= money then
            location.MoneyTool:Clone().Parent = game.Players[player.Name].Backpack
            local moneyTool = game.Players[player.Name].Backpack.MoneyTool

            moneyTool.Value.Value = money
            player.leaderstats.Money.Value = player.leaderstats.Money.Value - money
        else
            print(player.Name .. " does not have $" .. money)
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)
0
Updated to show the question is solved. M39a9am3R 3210 — 7y

1 answer

Log in to vote
0
Answered by
gitrog 326 Moderation Voter
7 years ago

Fixed it myself. For anyone who's having the same issue

local money = tonumber(message:sub(6))
0
why wouldn't you put [Solved] at the end instead of making an answer User#10445 15 — 7y
Ad

Answer this question