PlayerAdded does not want to run

I want to achieve something very simple that I have done multiple of times before.

I just want to add a value into the player when he gets added into the game but for some unknown reasons It does not do it. Is there anything did wrong? please let me know.

game.Players.PlayerAdded:Connect(function(player)
	print(player)
	local canDamage = Instance.new("BoolValue")
	canDamage.Name = "canDamage"
	canDamage.Parent = player
	print(player)
	canDamage.Value = false
end)
function sussify(p)
  --ur player script thingy
end

-- firing all the player exist [first player]
table.foreach(game.Players, function(i, p) sussify(p) end))

game.Players.PlayerAdded:Connect(sussify)
1 Like

Pretty sure table.foreach is deprecated, just use this

for i, p in pairs(game.Players:GetPlayers())

or

for i, p in next, game.Players:GetPlayers()

i believe table.foreach is better because it has no timeouts

deprecated but doesn’t mean can’t be used

1 Like

Players.Dev_Simphony.Backpack.Script:14: invalid argument #1 to ‘foreach’ (table expected, got Instance)

wait doesn’t that make it so it instances for everyone when 1 player joins?

oops

function sussify(p)
  --ur player script thingy
end

-- firing all the player exist [first player]
table.foreach(game.Players:GetPlayers(), function(i, p) sussify(p) end))

game.Players.PlayerAdded:Connect(sussify)