I am trying to make an RPG. But I'm really confused as this script isn't working. I mean, it works in Studio, but not online. I have also tried converting this script to a local script .
This script is supposed to buy a weapon in my game.
Here is the script.
script.Parent.MouseButton1Click:connect(function()
local RS = game:GetService("ReplicatedStorage")
local item = RS:WaitForChild("Old Sword")
local price = 100
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
if stats.Gold.Value == price then
stats.Gold.Value = stats.Gold.Value - price
local cloned = item:Clone()
local cloned2 = item:Clone()
cloned2.Parent = player.Backpack
cloned.Parent = player.StarterGear
end
end)
(server script)
I'd really appreciate it if anyone teaches me what I did wrong with this script.

2 comments
Also, can you explain why this is?
this is what?