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

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

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)

1 comment

0

Updated to show the question is solved.

1 answer

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

local money = tonumber(message:sub(6))

1 comment

0

why wouldn't you put [Solved] at the end instead of making an answer

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