The value goes negative

Hello everyone, I’m trying to do this when the player enters a value in the textbox (in this case TimeValue), then the TimeValue value will take from him as much as he entered and then will be converted into StageCoins. But I have a problem: when the player enters a value greater than he currently has, the value goes into a minus. I will be grateful for your help. here are the scripts:

local TimeValueChange = game.ReplicatedStorage:WaitForChild("TimeValueChange2")

TimeValueChange.OnServerEvent:Connect(function(player, amount)
	
	if player.TimeFolder.TimeValue.Value then
		
		player.TimeFolder.TimeValue.Value = player.TimeFolder.TimeValue.Value - amount
		
	end
	
end)

This server script is responsible for taking the TimeValue using RemoteEvent(this is where I got stuck).

local ConvertFrame = script.Parent:WaitForChild("ConvertFrame")
local TextBoxConvert = ConvertFrame:WaitForChild("TextBoxConvert")
local FinallyValue = ConvertFrame:WaitForChild("FinallyValue")
local ButtonConvert = ConvertFrame:WaitForChild("ConvertButton")

local player = game.Players.LocalPlayer

local TimeStats = player.TimeFolder:WaitForChild("TimeValue")

local TimeChange = game.ReplicatedStorage:WaitForChild("TimeValueChange2")

TextBoxConvert.Focused:Connect(function()
	
	TextBoxConvert:GetPropertyChangedSignal("Text"):Connect(function()
		
		FinallyValue.Text = TextBoxConvert.Text:gsub("%D+", "")
		
	end)
	
end)

ButtonConvert.MouseButton1Click:Connect(function()
	
	local text = TextBoxConvert.Text
	
	TimeChange:FireServer(text)
	
end)

This is a local script that, upon pressing a button, should take away from the player the TimeValue that he entered.

Instead of:
if player.TimeFolder.TimeValue.Value then
try
if player.TimeFolder.TimeValue.Value >= amount then

1 Like

This is what I give of course. I just added tonumber and it helped. @Pure_Bacn, Thanks for trying to help:)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.