Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
4D_X 118
6 years ago

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...

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

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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

Ad

Answer this question