Trouble getting leaderstats

image

If you are just getting the player through the remote event, you dont need to define it and you also do not need Player Service, You use Player Service on the client for the LocalPlayer or you use it on the Server to get all the players, or in other unrelated functions.

That error means to are adding a object and a number.

What I assume your doing

player.leaderstats.Clicks += 1 --error
Clicks is concidered an Instance, not a number

player.leaderstats.Clicks.Value += 1 --correct
Clicks.Value is the number.

thats MB in the other example, I type fast and forgot it.

I had this local button = script.Parent
local event = game.ReplicatedStorage.ClickEvent
local MarketPlaceService = game:GetService(“MarketplaceService”)
local GamePassID = 14905680
local player = game:GetService(“Players”).LocalPlayer
local clicks = player.leaderstats.Clicks
local userInput = game:GetService(‘UserInputService’)

button.MouseButton1Click:Connect(function()
event:FireServer()
player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1

if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassID) then
	player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 9
end    

end)

local function update_clicks()
player.PlayerGui.CLICK.Clicks.Text = "Clicks: "… tostring(clicks.Value)
end

clicks.Changed:Connect(function(update_clicks)
player.PlayerGui.CLICK.Clicks.Text = "Clicks: "… tostring(clicks.Value)
end)

userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.Space then
event:FireServer()
player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1

			if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassID) then
				player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 9
			end
		end
	end
end

end)

in the local script for the gui it was working, but it was not showing for the other players on the leaderstats.

You need to be adding the clicks on the server, Anything changed on the client will only be seen on the client. Adding Clicks on the client will only be visible by that single player.

--Client
button.MouseButton1Click:Connect(function()
   event:FireServer()
end)


--Server
RemoteEvent.OnServer:Connect(funtion(plr)

   player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1

   if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassID) then
     	player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 9
   end    

end)

Here the Client tells the Server that they clicked. The client takes that and adds the proper amount of clicks to the player’s leaderstats.