Problem with 'player' Argument

Hey! I was making a script that edits leaderstats when I ran into this problem while testing:

  19:37:27.957  player is not a valid member of Players "Players"  -  Server - checkRep:6

Here’s the code. I get it’s pretty clunky but it’s a wip:

local serverStorage = game:GetService("ServerStorage")
local repCount = serverStorage.repValues.repCount
local Players = game:GetService("Players")

local function checkForStat(player)
	local repLeaderstats = Players.player.leaderstats["Rep."]
	
	
	if repLeaderstats and repCount and repCount == 0 then
		repLeaderstats.Value = "Mixed"
		print("mixed")
	end
	
	if repLeaderstats and repCount and repCount == 1 then
		repLeaderstats.Value = "Good"
		print("good")
	end
	
	if repLeaderstats and repCount and repCount == 2 then
		repLeaderstats.Value = "Loved"
		print("loved")
	end

	if repLeaderstats and repCount and repCount == 3 then
		repLeaderstats.Value = "Heroic"
		print("heroic")
	end
	
	if repLeaderstats and repCount and repCount == -1 then
		repLeaderstats.Value = "Mean"
		print("mean")
	end

	if repLeaderstats and repCount and repCount == -2 then
		repLeaderstats.Value = "Cruel"
		print("cruel")
	end

	if repLeaderstats and repCount and repCount == -3 then
		repLeaderstats.Value = "Evil"
		print("evil")
	end
	
	
end

Players.PlayerAdded:Connect(checkForStat)

This might just be my inexperience speaking, but is there something wrong with the way I referenced the ‘player’ argument? I’ll take any advice.

Thanks
PikeEnthusiast

1 Like

Remove “Players”, since you already provided the player argument

2 Likes

I didn’t get an error, but the code didn’t work, nor did the print() commands.

1 Like

If the repcount is higher than 3 or lower than 3 then it will not print anything

1 Like

Could you elaborate? I’m sorry, I’m still learning scripting

1 Like

Players.player looks specifically for a player named “player”.
Instead, do Players[player.Name]

1 Like

Oh wait

Do you see that repCount? Change the second repCount to repCount.Value

	if repLeaderstats and repCount and repCount.Value == 0 then

Change that for the others

2 Likes

That worked for a while but because my code hates me leaderstats is no longer a valid member of ‘Players.ParkCityUSA’. This shows that the argument works, but when I tried using WaitForChild() it came back empty. Is there a fix?

What do you mean “it came back empty”. Can you provide how you get the leaderstats? (code snippet)

1 Like

Sure. It said it wasn’t a valid member of Players.ParkCityUSA. As for the code

local repLeaderstats = player.leaderstats["Rep."]
1 Like
local repLeaderstats = player:WaitForChild("leaderstats")["Rep."]

I know that you said it doesn’t work but this is just one of my solutions

2 Likes

Once again it works now, but the leaderboard isn’t updating the changes. I’ll just make this the solution because it’s technically the solution to my question. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.