Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Shop not taking my money when bought an item?

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)

2 comments

0

Fix your grammar lol... Idiot.

0

rude

1 answer

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.

2 comments

0

It didnt work, no errors or nothing.

0

oof, not sure.

This discussion is preserved as it was. New answers, comments, and votes are closed.