player.UserId is nil

I want to make a clicking gui, if you have a gamepass you get 5 clicks.

image

local button = script.Parent
local event = game.ReplicatedStorage.ClickEvent
local MarketPlaceService = game:GetService("MarketplaceService")
local GamePassID = 14531115
local player = game:GetService("Players")



button.MouseButton1Click:Connect(function(player)
	event:FireServer()
	print("yay working")
	leaderstats.Clicks.Value = leaderstats.Clicks.Value + 1
	
	if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassID) then
		leaderstats.Clicks.Value = leaderstats.Clicks.Value + 5
	end	
end)
1 Like

For the variable player you’re only calling on the service, not the actual LocalPlayer object.

1 Like

local player = players.LocalPlayer Could that be it?

1 Like

Yes, just make sure to rename your service variable.

local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
1 Like

It looks like you’re handling this on the client, I believe the player object will not be passed as argument if it’s client because you can simply do game.Players.LocalPlayer, but if you change it to a server script it should work
image

1 Like

Oh, I’ve realize you’re not using ClickDector.

1 Like

What would I change to a server script? You can’t fire the server on the server, right?

1 Like

I thought you were using a ClickDector because you had player as parameter, my bad, but you should move this part to the server.

1 Like
local button = script.Parent
local event = game.ReplicatedStorage.ClickEvent
local MarketPlaceService = game:GetService("MarketplaceService")
local GamePassID = 14531115
local player = game:GetService("Players").LocalPlayer

button.MouseButton1Click:Connect(function()
    event:FireServer()
    print("yay working")
   player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1
    
    if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassID) then
        player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 5
    end    
end)
1 Like

This doesn’t have anything to do with the issue but this can be rewritten as leaderstats.Clicks.Value += 1. It works just fine you’re way, I just think this looks more organized.

1 Like

Bad practice, don’t handle values on the client. Have the server handle that.

1 Like

Yep I know super exploitable, just fixing his script.

1 Like

What do you mean? Can you explain why?

1 Like

I wouldn’t call that a fix at all if you’re not improving his work practice.

You’re having values changed which will be replicated to all players. Any changes on client will NOT replicate to others.

2 Likes

Which means your data store will not recognize the changes, that’s why you should move the increment of clicks on the server.

1 Like