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

"string expected got nil" In a group door script (FE) What's wrong with it?

So this is a advanced (kinda) group door script.. Here's the server script:

game.Players.PlayerAdded:connect(function(plr)
game.ReplicatedStorage.OpenGDoor:FireClient(plr)
end)

And here's the client script:

game.ReplicatedStorage.OpenGDoor.OnClientEvent:connect(function(plr)
if game.Players[plr]:GetRankInGroup(3327521) >= 2 then -- This is where it errors out
workspace.GroupDoor:Destroy()
end
end)

welp...

1 comment

0

This is the full error: 17:48:47.804 - Players.Trolna.PlayerGui.LocalScript:2: bad argument #2 to '?' (string expected, got nil)

1 answer

✓ Accepted answer

because OnClientEvent doesn't give us a plr value we can just use game.Players.LocalPlayer because its a localscript

game.ReplicatedStorage.OpenGDoor.OnClientEvent:connect(function()
	if game.Players.LocalPlayer:GetRankInGroup(3327521) >= 2 then
		workspace.GroupDoor:Destroy()
	end
end)

Also you shouldn't use that plr variable like players[plr] to get the player, you should either just use plr.Character or game.Players:FindFirstChild(plr.Name).Character to get to the player because [] is used with strings for example workspace["testing 123'].PrimaryPart

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