Greetings,
I am getting some issues with this error and I don’t know how to fix it. The value flows through a remote event by the way. The code and error are down below.
The error:

The code:
button.MouseButton1Click:Connect(function()
local gems = 50
AddTrail:FireServer(tonumber(gems))
end)
AddTrails.OnServerEvent:Connect(function(gems)
addTrails(gems)
end)
function addTrails(gems)
local currency = player:WaitForChild("Currency"):WaitForChild("Gems")
currency.Value -= tonumber(gems)
end
Can you tell what’s the 87th line it’s getting error ?
currency.Value -= tonumber(gems)
Maybe try doing -
tonumber(currency.Value) -= tonumber(gems)

I don’t know if it works like that tbh
What I think is the gems value is nil.
Yea probably but then how am I supposed to send gems through?
button.MouseButton1Click:Connect(function()
local gems = 50
AddTrail:FireServer(gems)
end)
Basically it removed the tonumber()
Hi, yes the Gem value is nil.
You do not need to use tonumber on the client. On the client send the gems amount directly, on the server, check if gems is a number before doing anything else.
Also, I would not suggest that you send values from the client to the server, since the client can send the number 1 million instead of 50.
2 Likes
Also, try printing the gems value and see if it’s nil.
1 Like
I think the solution would be -
Don’t use tonumber
Print gems value and see if it’s nil.
Quick Tip-
Always print a value to avoid confusion and see if the value you desired is there.
Well I need to send to the server…
Why do you need to send it to the server?
Is it a shop?
When I first made the script I did not use tonumber and it gave me the same error, and yes it is nil.
1 Like
I want to make an universal system so I don’t have to make tens of blocks of code that just remove gems from the datastore of a player. I am using the server side to remove the gems so afterwards I can save them to the player’s userid
I do not quite get the universal part.
You should not send the cost of something to the server from the client. Instead you should send from the client to the server, what they wish to buy. (This is just a sample if it was a shop. Since you did not specify if it was a shop or not)
With your current code they can also give themself gems, by sending a negative number. Since negative + negative = positive.
1 Like
Try to remove all the tonumber()
I have done that the first time and no luck
He has sent from client to server as he used :FireServer()