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.
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)
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)
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)
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.
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).