Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this not lock players when it locks the rest of workspace?

I tried to do just a simple code, which works for the most part

for i,v in pairs(workspace:GetDescendants()) do
    if v:IsA('BasePart') then
        v.Locked = true	
	end
end

The rest of the script just unlocks certain things (none of which would select a player). Am I missing something? Probably something simple I'm just totally overlooking but appreciate the help.

1 answer

First off Players are already locked.

But if you really need it:

Solution: The script runs whenever the server is online, not when a player joins. We can easily run the script whenever the player joins by adding it in a PlayerAdded() function.

Code:

game.Players.PlayerAdded:Connect(function(plr)
wait(1.2)
for i,v in pairs(workspace:GetDescendants()) do
	if v:IsA('BasePart') then
		v.Locked = true 
	   end	
	end
end	

5 comments

0

I had already tried this and I had used playeradded before, but it doesn't seem to work correctly still. This is why I was wondering if there was an issue with those lines of code themselves, where they wouldn't act on players. When going in and viewing properties of the parts within the player, they are still not locked.

0

alright, but players are already locked tho

0

But the locked property is not enabled? When testing the game, it was still possible to modify players with tools that check for this property.

0

check it on the server, its locked

0

Also edited it should work now

This discussion is preserved as it was. New answers, comments, and votes are closed.