I need a value to count up something that's for all players, but I don't know how. For example Player1 clicks on a button and the value goes +1 (so now it's 1) Player 2 does the same now the value is 2.
I need it for a egg hatching system to count the amount of each pet that is hatched.
This can be done very easily by creating a single value and adding to the value every time an egg is hatched.
local EggsHatched = workspace.Values.EggsHatched -- Assuming the value "EggsHatched" is in workspace inside a folder called Values. -- Run this code on the server below every time an egg is hatched. EggsHatched += 1
If you want to read the value on the client put the NumberValue inside a place accessable to the client, such as ReplicatedStorage or Workspace.
When checking the clicks on the client you would need a remote event to communicate with the server about adding to the value. Read more about remote events here.
If you need this value to be saved i would suggest looking into the DataStoreService.
You can add a number value and place it somewhere like Players, then add a number value in players when they join, and then when the number value in Players updates, you change all the players' number values to the value of the number in Players.
local Players = game:GetService("Players") local NumberValue = Players:WaitForChild(YourNumberValue) Players.PlayerAdded:Connect(function(Player) if Player:FindFirstChild(ValueName) then Player:FindFirstChild(ValueName):Destroy() end local Value = Instance.new("NumberValue") Value.Name = ValueName Value.Value = NumberValue.Value Value.Parent = Player NumberValue:GetPropertyChanged:Connect(function() Value.Value = NumberValue.Value end) end)