Hello, I made a script opening a door if the player touching it has a certain rank in a group, which works, but the part getting a player from character does not seem to work (after the rank detection, the script continue but I've choose not to include it). Here, hit is the character touching the door.
function Move(Hit) local Character = Hit.Parent local Player = game.Players:GetPlayerFromCharacter(Character) if Player == nil then print("Nil.") end print("Door " .. script.Parent.Name .. " detected player " .. Player.Name .. ", checking rank.") if Player:GetRankInGroup(4274321) >= 251 and Player:IsInGroup(4274321) then
The output is this:
Nil. 10:23:49.829 - Workspace.GroupLightDoor1.Script:21: attempt to index local 'Player' (a nil value) 10:23:49.830 - Stack Begin 10:23:49.830 - Script 'Workspace.GroupLightDoor1.Script', Line 21 10:23:49.830 - Stack End Door GroupLightDoor1 detected player CreatorMan2006, checking rank.
When I play the game in studio, and walks to the door, it opens, but errors "attempt to index local 'Player' (a nil value)". From what I know, nil is something that does not exist. If the player was nil, the door shouldn't be able to open since it could not detect the player's rank. This error does not ruin the game, but each time the door opens, it throws the error, and I don't know how to get rid of it.
Try adding these checks. This checks if the part that touched the door is a player and isn't nil.
if Player ~= nil and hit.Parent:FindFirstChild("Humanoid") then --Rest of the code end