Hi, so I'm trying to make a script where when any player (except the local player) in the server is within 20 distance from a part, that part anchors, and when they aren't, the part unanchors. I'm using DistanceFromCharacter to do this.
for _, player in pairs(game.Players:GetPlayers()) do if player.Name ~= game.Players.LocalPlayer.Name then game:GetService('RunService').Stepped:connect(function() if player:DistanceFromCharacter(game.Workspace.part.Position) < 20 then game.Workspace.part.Anchored = true else game.Workspace.part.Anchored = false end end) end end
When I tested this out, it was not working and I was confused, when I realised it only worked on one player and was not detecting all players within a distance of 20. How would I change my code to make it so that if any player in the server is within that distance to anchor it, instead of only one player?