Leaderstats is not a valid member of Player "player.alabamalover90001"

Hello, I am currently making a simulator and I am making a gym door that allows you to walk through it whenever your leaderstats value is >= the value I set it.

Currently I am getting this error I have NEVER ran into.

image

Code:

game.Players.PlayerAdded:Connect(function(player)
	if player.leaderstats.MusclarCash.Value >= 10000 then
		script.Parent.CanCollide = false
	else
		script.Parent.CanCollide = true
	end
end)

Please help me resolve this!

A.S.A.P

I mean it’s 1 of four things.

  1. You’re not adding in leaderstats folder under the player anywhere.

  2. You misspelled leaderstats

  3. You’re not allowing sufficient time for leaderstats to load in. Solve by using :WaitForChild()

  4. You added leaderstats in from a local script and are trying to reference it globally.

4 Likes

This is not a local script, but I could see the instance WaitForChild() I could use.

If throwing in WaitForChild() results in a infinite yield please send me the script where you are inserting the player’s leaderstats folder, and what type of script it is.

This still isn’t working, but I am not getting any output.

So basically, the door will not allow / cancollide.

game.Players.PlayerAdded:Connect(function(plr)
if plr:WaitForChild("leaderstats").MusclarCash.Value >= 10000 then
script.Parent.CanCollide = false
else
script.Parent.CanCollide = true
end
end)

Are you adding in a leaderstats folder anywhere???
Because in this script you aren’t adding in one.

local Folder = instance.new("Folder", player)
Folder.Name = "leaderstats"

In game open up explorer Players > you > see if there is a leaderstats folder.
If there is click swap to server, and do the same thing.

Yes I have added a leaderstats folder.

please show us the script where you add it

The script is inside server script service, dont worry about the leaderstats and if I added it.

One sec… is this script inside like a part?

yes it is inside a part, it used to be a script, but i tried a local script but it didnt work, i’ll still use a normal script if it works.

Here I have a solution for you, just give me a second to test it out.

Oh wait a minute. This isn’t even that complicated. In your leaderstats script, make a condition if the player’s muscle thing value is greater than the amount you want it then the part’s can collide property is false.

I tested this code out in studio and it works perfectly.

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local musclestuff = Instance.new("IntValue", leaderstats)
	musclestuff.Name = "MuscleCash"
	musclestuff.Value = 0
	if musclestuff.Value >= 10000 then
		game.Workspace.Part.CanCollide = false
		print("False")
	else
		print("Not enough")
	end
end)

Now, if you wanted to make these local, then you would want to use a remote event. Make a remote event inside replicated storage and then make a local script inside starter player scripts, and then type this code.

leaderstats script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local musclestuff = Instance.new("IntValue", leaderstats)
	musclestuff.Name = "MuscleCash"
	musclestuff.Value = 0
	if musclestuff.Value >= 10000 then
		game.ReplicatedStorage.RemoteEvent:FireClient(player)
		print("False")
	else
		print("Not enough")
	end
end)

local script:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	game.Workspace.Part.CanCollide = false
end)

Sorry for the long post but hope this helped you with your problem!

I tried the exact same thing as you did basically.

Basically, but I feel like you should use this method, especially because what you are doing currently isn’t working.

This is exactly the reason why your current code is failing though. Need to see that code.

1 Like

try this
game.Players.PlayerAdded:Connect(function(player)
if player:WaitForChild(“leaderstats”).MusclarCash.Value >= 10000 then
script.Parent.CanCollide = false
else
script.Parent.CanCollide = true
end
end)

The problem is that since it says “PlayerAdded”, it would only be available if you joined whilst having over 10000 value, it wouldn’t be available if you joined before you had 10000 value and just reached 10000 value, you should make it so you’d make a loop where it’ll see if the player will have more or less than 10000 or equal.

Also “MusclarCash”? You probably mispelled it, anyways fix your other scripts and answer people’s common sense questions so you’d get it finished rq.

So basically, my leaderstats script is a datastore + leaderstats, maybe that’s why, I don’t know.

local DService = game:GetService("DataStoreService"):GetDataStore("Game")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local MusclarCash = Instance.new("NumberValue")
	MusclarCash.Parent = leaderstats
	MusclarCash.Name = "MusclarCash"
	
	local Strength = Instance.new("NumberValue")
	Strength.Parent = leaderstats
	Strength.Name = "Strength"
	
	local Rebirths = Instance.new("NumberValue")
	Rebirths.Parent = leaderstats
	Rebirths.Name = "Rebirths"
	
	local debounce = Instance.new("BoolValue")
	debounce.Parent = player
	debounce.Name = "Debounce"
	
	if player.leaderstats.MusclarCash.Value >= 10000 then
		game.Workspace.GymDoor.CanCollide = false
		game.Workspace.GymDoor.Anchored = true
	else
		game.Workspace.GymDoor.CanCollide = true
	end
	
	local key = "user-"..player.UserId
	
	local storedItems = DService:GetAsync(key)
	
	if storedItems then
		MusclarCash.Value = storedItems[1]
		Strength.Value = storedItems[2]
		Rebirths.Value = storedItems[3]
	else
		local items = {MusclarCash.Value, Strength.Value, Rebirths.Value}
		
		DService:SetAsync(key, items)
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	local items = {player.leaderstats.MusclarCash.Value, player.leaderstats.Strength.Value, player.leaderstats.Rebirths.Value}
	
	local key = "user-"..player.UserId
	
	DService:SetAsync(key, items)
end)

I put it above the data store.

While in testing mode check to see if the values are inside a “leaderstats” folder inside the player (In Players). If there is all the data then your leaderstats will not be the problem, if in case it is the problem make sure you didn’t miss-spell anything.

Also maybe add and load the key before the statement:
take the "if player.leaderstats.MusclarCash.Value >= 10000 then
and put it under the “game.players.playerremoving” ( I meant after the entire thing so put it under the end).