So I was making a shop system to improve on one I made a while ago that dont work anymore and I keep getting the error in the title. FYI the event passes through the player, the amount of the item and the item from the client
Here is code
the error is on if leaderstats.Coins.Value >= amount then
local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("Purchase")
event.OnServerEvent:Connect(function(player, amount, item)
local leaderstats = player.leaderstats
local coins = leaderstats.Coins
if leaderstats.Coins.Value >= amount then
coins.Value -= amount
print("Succesful Purchase")
local item = RS:FindFirstChild(item)
local clone = item:Clone()
clone.Name = item.Name
clone.Parent = player.Backpack
end
end)
local button = script.Parent
local players = game.Players
local player = players.LocalPlayer
local amount = 100
local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("Purchase")
local item = "Sword"
button.MouseButton1Down:Connect(function()
event:FireServer(player, amount, item)
end)
You don’t need to fire the local player since the first parameter bolded above will always have the player that fired the event. It’s given to you automatically. So keep that line as it is.