It says there is an error on line 4 (Argument 1 missing or nil), I don't know what this means, thanks!
script.Parent.MouseButton1Click:Connect(function() local name = script.Parent.Name.Text local potatoes = script.Parent.Potatoes.Text if game.Players:FindFirstChild(name) then game.Players:FindFirstChild(name).leaderstats.Potatoes.Value = game.Players:FindFirstChild(name).leaderstats.Potatoes.Value + potatoes(tonumber()) end end)
"Argument missing or nil" means that the argument hasn't been passed or doesn't exist.
In example, if the player you are trying to find doesn't exist, it is said to be "nil".
You should also create a variable for your player, it will be easier to reference it that way!
local players = game:GetService("Players") local player = players[name] -- And use if(player) then -- if the player is found, run your code end
Warning! You are trying to change a user's stats from a LocalScript, meaning that it will only change for you, or the user who's using it! In order to makes changes that are seen by everyone, you need to learn to use "RemoteEvents"!
There is good documentation and examples in Roblox's documentation!
Documentation on:
Remote event server script
game.ReplicatedStorage.PotatoesCommand.OnServerEvent:Connect(function(player, name, potatoes) print(name) print(potatoes) print("yes") local players = game:GetService("Players") local plr = players[name] if (plr) then plr.leaderstats.Potatoes.Value = plr.leaderstats.Potatoes.Value + tonumber(potatoes) end end)
Local Script
script.Parent.MouseButton1Click:Connect(function() local name = script.Parent.Name.Text local potatoes = script.Parent.Potatoes.Text if name ~= "" and potatoes ~= "" then game.ReplicatedStorage.PotatoesCommand:FireServer(name, potatoes) end end)