I am trying to make a refund option in my mod panel. Here is my code:
local Button = script.Parent.Parent.Submit.TextButton
local Amount = script.Parent.Parent.Parent.Refund.Amount.TextBox.Text
Button.MouseButton1Click:connect(function()
local Player = script.Parent.Parent.Username.TextBox.Text
local PlayerFound = game.Players:FindFirstChild(Player)
if PlayerFound then
game.Players:FindFirstChild(Player).leaderstats.Points.Value = game.Players:FindFirstChild(Player).leaderstats.Points.Value + Amount
game.Players:FindFirstChild(Player).leaderstats.Wins.Value = game.Players:FindFirstChild(Player).leaderstats.Wins.Value + Amount
Amount = "Amount"
Player = "Username"
end
end)
However, when I click submit, I am getting this error:
attempt to perform arithmetic (add) on number and string
I would appreciate it if someone could please help me out. Thanks.
How do you know it’s double?
Trying printing type(value) to both of these value see what does it return? as proven by the error message, you’re adding double to string.
Btw, unless you’re on vanilla Lua, you can do (this is a new feature)
local Button = script.Parent.Parent.Submit.TextButton
local Amount = script.Parent.Parent.Parent.Refund.Amount.TextBox.Text
Button.MouseButton1Click:Connect(function()
local player = script.Parent.Parent.Username.TextBox.Text
local PlayerFound = game.Players:FindFirstChild(player)
if PlayerFound and type(tonumber(Amount)) == "number" then
game.Players:FindFirstChild(Player).leaderstats.Points.Value =
game.Players:FindFirstChild(Player).leaderstats.Points.Value + tonumber(Amount)
game.Players:FindFirstChild(Player).leaderstats.Wins.Value =
game.Players:FindFirstChild(Player).leaderstats.Wins.Value + tonumber(Amount)
end
end)
Did you even check the type of the Amount and the game.Players:FindFirstChild(Player).leaderstats.Wins.Value (or whatever you’re adding)?
You have exemplified the importance of type checking.
That does not answer my question. What will amount equal?
Also, this should NOT be on the client entirely, I can assure you you will run into problems after you fix this error. The value should 10)% of the time be changed on the server side.