Player can't go through the wall even though their in the group?

I want the player to go through the wall if they are admins or up in my group.

The issue is that I’m getting this error:

 GetRankInGroup is not a valid member of Part "Workspace.LMVM2041.Nerd Glasses.Handle" 

Code

local groupid = 8001185

script.Parent.Touched:Connect(function(Player)
	if Player:GetRankInGroup(groupid) >= 150 then
		script.Parent.CanCollide = false
		wait(0.5)
		script.Parent.CanCollide = true
	else
		print("Unauthorized player detected!")
	end
end)

Anybody know what I did wrong?

Touched would return the part that touched script.Parent. You need to get the Player from the part that was touched. You could try something like this:

local Players = game:GetService'Players'
local groupid = 8001185

script.Parent.Touched:Connect(function(touched)
    -- get player from "touched.Parent" (player character in most cases)
    local Player = Players:GetPlayerFromCharacter(touched.Parent)
    -- if the part that touched didn't belong to a player's character, then do nothing
    if not Player then return end
	if Player:GetRankInGroup(groupid) >= 150 then
		script.Parent.CanCollide = false
		wait(0.5)
		script.Parent.CanCollide = true
	else
		print("Unauthorized player detected!")
	end
end)
2 Likes

To add on, it’s also better to teleport the player, or do it locally.

I wouldn’t want to teleport the player. I just want those who have access (in group and specific rank) to go through a wall/door.

Then in that case it’d be better to do it locally since other players can go though in those 0.5 seconds.

It would be advised to call this locally instead. As @RipPBB_TUD already stated, users could cheat their way into the area by going in simultaneously with the user in the group since it’s server-sided.

2 Likes