I'm trying to make a shop but when I try to buy things in the store this error comes


script.Parent.MouseButton1Click:connect(function()
 local RS = game:GetService("ReplicatedStorage")
 local item =  RS:WaitForChild("Sword")
 local price = 0 -- Change Your Price Here
 local player = game.Players.LocalPlayer
 local stats = player:WaitForChild("leaderstats")
 
 if stats.Robux.Value == price then -- Change the Money to your Currency Name
  stats.Money.Value = stats.Money.Value - price
  local cloned = item:Clone()
  local cloned2 = item:Clone()
  cloned2.Parent = player.Backpack
  cloned.Parent = player.StarterGear
 end
end)

in line 6

5 comments

0

What error comes?

0

23:10:14.124 - Players.Dima_Games666.PlayerGui.SHOP.Frame.Frame.item1.Script:6: attempt to index local 'player' (a nil value)

0

i know "it's not local script" is the reason that player is nil. LocalPlayer is strictly client-only but i dont know how to fix it

0

Take all your code, place it in a LocalScript, at the same place as your current Script. You should not use Server Scripts in Guis

0

Techically s scripts only work for some gui elements like textbuttons