Negative Number Money Giver System

I’m currently attempting to make a money give system in which when the player enters the username and amount of money they wish to send, it will drop a money bag for that player to pick up and receive the given money. This system works fine except for one primary issue. If the player enters a negative number such as “-10” or “-100” it will give them money from nowhere. I attempted to make the code have a

if value < 0 then

But it will not work. Any help?

script.Parent.MouseButton1Click:Connect(function()
	local money = script.Parent.Parent.amount.Value
	local GUI = script.Parent.Parent.Parent.Frame.TextBox.Text
	local send = script.Parent.Parent.username.Value
	if game.Players.LocalPlayer.leaderstats.Lyr.Value >= script.Parent.Parent.amount.Value then
		if game.Players:FindFirstChild(send) then
			game.ReplicatedStorage.Money:FireServer(send, money)
			script.Parent.Parent.userna.Text = ''
			script.Parent.Parent.TextBox.Text = ''
		end
	end
end)

For reference the money name is a ‘Lyr’

You can check if string.match(value,"-") then print (“Nope”) else --give money end

Unsure if this is just a mistake in the post but, if not you were checking if the number was less than 0.
Assuming this was the mistake, use this.

if value > 0 then
1 Like

You could math.abs() the value they enter to make it always positive.

1 Like
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")
local Lyr = Leaderstats:WaitForChild("Lyr")

local Replicated = game:GetService("ReplicatedStorage")
local Money = Replicated:WaitForChild("Money")

local Button = script.Parent
local Frame = script.Parent.Parent

Button.MouseButton1Click:Connect(function()
	local Money = Frame.amount.Value
	local SendTo = Frame.username.Value
	if Lyr.Value >= Frame.amount.Value then
		local Receiver = Players:FindFirstChild(SendTo)
		if Receiver then
			Money:FireServer(Receiver, Money)
			Frame.userna.Text = ''
			Frame.TextBox.Text = ''
		end
	end
end)

This worked. I tried this earlier but I do not think I did it right. Thanks!

1 Like