whenever it buys it takes the money for like 3 seconds and the money comes back and the tool is still in my inventory ://
local price = script.Parent.Parent.Price local tools = game.ReplicatedStorage:WaitForChild("Library") local tool = script.Parent.Parent.ItemName local player = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function() if player.leaderstats:FindFirstChild("Cash").Value >= price.Value then player.leaderstats:FindFirstChild("Cash").Value = player.leaderstats:FindFirstChild("Cash").Value - price.Value game.ReplicatedStorage.ShopBuy:FireServer(tool.Value) end end)
Hello, It's because your code is client sided, the server changes your money back to it's original form. To fix this you'll need to make it server-sided by using RemoteEvents
Here you go I made an example for you :
LocalScript
local price = script.Parent.Parent.Price local tools = game.ReplicatedStorage:WaitForChild("Library") local tool = script.Parent.Parent.ItemName local player = script.Parent.Parent.Parent.Parent.Parent.Parent script.Parent.MouseButton1Click:connect(function() if player.leaderstats:FindFirstChild("Cash").Value >= price.Value then game:GetService("ReplicatedStorage").RemoteEvent:Fire(price.Value,tool.Value) end end)
ServerScript
local Remote = Instance.new("RemoteEvent",game:GetSerivce("ReplicatedStorage")) local tools = game.ReplicatedStorage:WaitForChild("Library") Remote.OnServerEvent:Connect(function(player,price,tool) local usercash = player.leaderstats:FindFirstChild("Cash") if usercash.Value >= price then usercash.Value = usercash.Value - price tools[tool]:Clone().Parent = player.Backpack end end)
Feel free to comment if there's any bugs or you need more help.