"player is not a valid member of Players 'Players'"

I have been trying to make a simple function using a ProximityPrompt and a part that reduces an in game leaderstats currency and have the recurring issue of the function title “player” not being considered a player in game.Players. Any help would be much appreciated.

script.Parent.ProximityPrompt.Triggered:Connect(function(player)

	player.leaderstats.smackDollars.Value = player.leaderstats.smackDollars.Value - 100

	player.Backpack.Shmack:Destroy()

	game.Workspace.Shmack2.Parent = player.Backpack

	script.Parent.ProximityPrompt:Destroy()
end)
1 Like

I think you should check if the player exists first, then run the rest of the code.

Try and see if this code works:

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	if player then
		player:WaitForChild("leaderstats").smackDollars.Value -= 100

		player:WaitForChild("Backpack").Shmack:Destroy()

		game.Workspace.Shmack2.Parent = player.Backpack

		script.Parent.ProximityPrompt:Destroy()
	end
end)
2 Likes

On which line is the error exactly? I can’t see a problem here

Thank you this really helped. I appreciate the support.

1 Like