this is a localscript that fires a remote that charges the player $300 for a baseball bat however it only works once then it doesn't work the second time and comes up with an error.Also my guy had enough money
script.Parent.MouseButton1Click:Connect(function() local plr=game.Players.LocalPlayer local cash=plr.Data.Wallet if cash.Value>=300 then local event=game.ReplicatedStorage.backpack event:FireServer("Baseball Bat",300) script.Parent.Parent.Visible=false end end)
The error is on the remote script's line 8
game.ReplicatedStorage.backpack.OnServerEvent:connect(function(plr,Message,cost) local pack=game.ServerStorage.Tools:FindFirstChild(Message) local cash=plr.Data.Wallet cash.Value=cash.Value-cost pack:Clone() pack.Parent=plr.Backpack end)
error: https://gyazo.com/8da86a9c465e60591667ff85c24109a6
game.ReplicatedStorage.backpack.OnServerEvent:connect(function(plr,Message,cost) if not Message then print("Invalid Item") return end local serverStorage = game:GetService("ServerStorage") local pack = serverStorage.Tools:WaitForChild(Message) local cash = plr.Data.Wallet cash.Value = cash.Value - cost pack:Clone() pack.Parent = plr.Backpack end)
Try this maybe it will work for you.
When you go to clone the item, dont make the variable and then clone. I believe you are actually just moving the item from replicated storage to the players Backpack. do this instead
game.ReplicatedStorage.backpack.OnServerEvent:connect(function(plr,Message,cost) local pack=game.ServerStorage.Tools:FindFirstChild(Message):Clone() -- add clone here local cash=plr.Data.Wallet cash.Value=cash.Value-cost pack.Parent=plr.Backpack end)