So i am trying to make a shop script and when the player purchases something it fires to the server, here is the code for that
script.Parent.MouseButton1Click:Connect(function()
local toolname = script.Parent.Parent.Itemname.Text
local cost = script.Parent.Parent.Price.TextLabel.Text
local tool = game.ReplicatedStorage.Tools[toolname]
local money = script.Parent.Parent.Parent.Parent.Parent.Parent
game.ReplicatedStorage.Purchase:FireServer(money, toolname, cost, tool)
end)
then the server makes sure that the player has enough money to purchase the item, but when i test it i get an error saying attempt to compare userdata value and nil here is that script
game.ReplicatedStorage.Purchase.OnServerEvent:Connect(function(money, tool, cost)
local money = money
if money >= tonumber(cost) then
money = money - cost
local tool = tool:Clone()
tool.Parent = game.Players.LocalPlayer.Backpackk
end
end)

6 comments
it says for line 5, attempt to call a nil value
That's not supposed to happen..
Which script is it?
2nd one
LocalScript or ServerScript?
Server