game.Players.PlayerAdded:Connect(function(plr) local a = Instance.new("Folder",plr) a.Name = "leaderstats" local m = Instance.new("IntValue",a) m.Value = 0 m.Name = "Cash" local x = Instance.new("IntValue",a) x.Value = 0 x.Name = "Bananas" end) while true do wait(1) for i, v in pairs(game.Players:GetChildren()) do if v:FindFirstChild("leaderstats") ~= nil then if v.leaderstats:FindFirstChild("Bananas") ~= nil then if game.Players.LocalPlayer.leaderstats.Cash.Value == 0 then v.leaderstats.Bananas.Value = v.leaderstats.Bananas.Value else v.leaderstats.Bananas.Value = v.leaderstats.Bananas.Value +10 end end end end end
Network filtering, more commonly know as FilteringEnabled
, or FE
is the main cause of your problem here. As the server does not have a local player.
You can think of asking the server to get the local player as:
Safe to say, it just creates a whole lot of confusion.
what you can do to avoid this is by using the players table you already have, instead of use the local player, like this:
lua
for _,plr in pairs(game.Players:GetPlayers()) do
local ls = plr:FindFirstChild("leaderstats")
if ls then
if not (ls.Cash.Value == 0) then
ls.Bananas.Value = ls.Bananas.Value + 10
end
end
end
GetPlayers()
instead of GetChildren()
to avoid getting non-player objectsif not x then ...
, rather than doing if x then else ...
if not x
, rather than if x ~= nil
, assuming the value you are trying to get isn't false
, as both false and nil are falsey valuesHopefully this helped