WATCH THIS IF YOU DONT UNDERSTAND WHAT IM SAYING: https://streamable.com/gwjcgm
I've made a SurfaceGui button with a RemoteEvent that should decrease the value "PrinterLimit" in game.Players.LocalPlayer, but it just does not work and gives me the error: "player argument must be a Player object" or "Argument 1 missing or nil".
Here's the script inside the button that should decrease the value.
local repStorage = game:GetService("ReplicatedStorage") local DeletePrinter = repStorage.DeletePrinter script.Parent.MouseButton1Click:Connect(function(Player) DeletePrinter:FireClient(Player) Player.PrinterLimit.Value = Player.PrinterLimit.Value - 1 end)
And the LocalScript inside StarterPlayerScripts called DecreasePrinterLimit
local repStorage = game:GetService("ReplicatedStorage") local DeletePrinter = repStorage.DeletePrinter DeletePrinter.OnClientEvent:Connect(function(player) print(player.Name.."just destroyed a printer!") end)
Two things: .MouseButton1Click doesn't have any arguments. Second: .OnClientEvent doesn't have player as the first argument, only the arguments you pass by :FireClient(). So fixing those problems you have:
-- server script local repStorage = game:GetService("ReplicatedStorage") local DeletePrinter = repStorage.DeletePrinter game.Players.PlayerAdded:Connect(function(player) -- we are gonna get the player from the playerAdded event script.Parent.MouseButton1Click:Connect(function() DeletePrinter:FireClient(player) player.PrinterLimit.Value -= 1 -- use -= operator end) end)
and
-- local script local repStorage = game:GetService("ReplicatedStorage") local DeletePrinter = repStorage:WaitForChild("DeletePrinter") -- just in case local player = game.Players.LocalPlayer -- we got the player here DeletePrinter.OnClientEvent:Connect(function() -- no player argument print(player.Name.."just destroyed a printer!") end)
Hope this fixed your problem