Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Shop not taking my money when bought an item?

Asked by 4 years ago

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)

0
Fix your grammar lol... Idiot. apexslab 15 — 4y
0
rude AnasBahauddin1978 715 — 4y

1 answer

Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
It didnt work, no errors or nothing. FaZeMcKid 0 — 4y
0
oof, not sure. VitroxVox 884 — 4y
Ad

Answer this question