So, i was making an coin to cash and cash to coin exchange but when i tried to get the number from the text box it says: "attempt to perform arithmetic (add) on number and string." even though i check if its a number when the exchange button is clicked, so i still dont get it... Can you help?
Scripts:
Exchange script (script, server script service):
local cct = game.ReplicatedStorage.remoteEvents.exchange.cointocash
local ccbt = game.ReplicatedStorage.remoteEvents.exchange.cashtocoin
local txtbox = game.StarterGui.ccexhanfe.Frame.COIN.ccframe1.TextBox
local st = game.ReplicatedStorage.ST
cct.OnServerEvent:Connect(function(player, amntD, sta)
local thisplr = game.Players:findFirstChild(player.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local cash = stats:findFirstChild("Cash")
local coin = stats:findFirstChild("Coins")
if (cash~=nil) then
cash.Value = cash.Value + txtbox.Text
st.Value = "SUCCESS!"
end
end
end
end)
Button script (local script, starter gui):
local txtbox = script.Parent.Parent.TextBox
local sta = game.ReplicatedStorage.ST
local amntD = txtbox.Text
local cct = game.ReplicatedStorage.remoteEvents.exchange.cointocash
script.Parent.MouseButton1Click:Connect(function()
if tonumber(txtbox.Text) then
sta.Value = "WORKING ON IT!"
wait(3)
cct:FireServer(amntD, sta)
else
sta.Value = "Please enter a number!"
end
end)
Dont judge me for using a StringValue, i will fix that soon, its just for test purposes. Also i tried the tonumber(txtbox.Text) that doesnt work either... it says: attempt to perform arithmetic (add) on number and nil

7 comments
txtbox.Text is a String. Can't use it in math
And you're using StarterGui. Which is not correct actually. Read up about it. You should check the players' PlayerGui
Then how do i get the number
I tried the tonumber but that doesnt work either
Well you should use tonumber on the text. But you're getting the text the wrong way. Try sending it via the RemoteEvent
Ok, i will try that. I will let you know if it works or not.
Oh, it works!! Thank you!