Shop system not working

I am making a simple shop system with a gui, but it won’t work

This is running in a local script

local item = script.Parent.Parent:WaitForChild("1Name").Text --this is a random shop so this just tells what the item is
local plr = game.Players.LocalPlayer
local ls = plr:WaitForChild("leaderstats")
local coins = ls:WaitForChild("Slung coins").Value
local inv = plr.Backpack
local tool = game.ServerStorage.Tool
local pricetag = script.Parent.Parent:WaitForChild("1Price")
local price = tonumber(pricetag)

script.Parent.MouseButton1Up:Connect(function()
	if coins >= price then
		coins = coins - price
		local newtool = tool:Clone()
		newtool.Name = item
		newtool.Parent = inv
	end
end)
1 Like

running in server script via RemoteEvent

you need to use remote event to do the purchase

I dont know how this would work because there are multiple things in the shop

My guess here is that it’s because you’re doing it with a LocalScript, which means whatever you’re doing in it won’t replicate to the server, for me I would use a RemoteEvent, put it in ReplicatedStorage, name it whatever you think is best

local item = script.Parent.Parent:WaitForChild("1Name").Text --this is a random shop so this just tells what the item is
local plr = game.Players.LocalPlayer
local ls = plr:WaitForChild("leaderstats")
local coins = ls:WaitForChild("Slung coins").Value
local inv = plr.Backpack
local tool = game.ServerStorage.Tool
local pricetag = script.Parent.Parent:WaitForChild("1Price")
local price = tonumber(pricetag)

local remoteEvent = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Up:Connect(function()
	if coins >= price then
       remoteEvent:FireServer(coins, tool)
	end
end)```


Now in a normal script in ServerScriptService:
```lua
local remoteEvent = game.ReplicatedStorage.RemoteEvent
remoteEvent.OnServerEvent:Connect(function(player, coins, tool)
    coins = coins - price
    local newTool = tool:Clone()
    newTool.Parent = player.Backpack
end)

I have no idea why the text markup isn’t working I’m sorry if it looks ugly