-----Group 1---- GroupId = 921838 min = 1 max = 255 -----Group 2---- GroupId2 = -1 min2 = -1 max2 = -1 --Specific Settings-- Door = script.Parent Debounce = false local teleportto = game.Workspace.OutsideDoor local location = {teleportto.Position} local x = location[1].x local y = location[1].y local z = location[1].z ---------- --Script-- ---------- function Touched(Part) local Human = Part.Parent:findFirstChild("Humanoid") if Human ~= nil then print("Work") if Debounce then return end Debounce = true if Part.Parent then print("Work2") print("Work3.1") if Human.Parent:GetRankInGroup(GroupId) >= min and Human.Parent:GetRankInGroup(GroupId) <= max or Human.Parent:GetRankInGroup(GroupId2) >= min2 and Human.Parent:GetRankInGroup(GroupId2) <= max2 then print("work4") Human.Parent.Character.Torso.CFrame = CFrame.new(Vector3.new(x,y,z)) print("Work5") else Part.Parent:breakJoints() script.Parent.Denied:play() end end end Debounce = false Door.Touched:connect(Touched)
So what I am trying to do is make a new group only door, but this is the error I get. The parts that the player will get teleported are linked correctly. And what I mean by that is that they are in the right spot in the game explorer. The below answer did help but now a new error has arisen, sorry for the inconvenience and question asking. :( Any help is appreciated! :D
21:05:46.604 - GetRankInGroup is not a valid member of Model 21:05:46.606 - Script 'Workspace.Group Rank Only Door V1.5.1.Door.Group Rank Based', Line 29
The problem here is that anything that touches the door can trigger the script. Imagine if a random part in the workspace touched the door. The script would index "human" as the part's parent' Humanoid. Obviously a random part wouldn't have a Humanoid, so "human" is indexed as nil (does not exist). So when the script uses the human variable it can't function since human is nil! To fix this, use an if statement.
function Touched(Part) local Human = Part.Parent:findFirstChild("Humanoid") if Human ~= nil then --If the humanoid exists then
Human.Parent
is a character model in the Workspace. However, :GetRankInGroup()
only works for the Player Instance under game.Players
. So, perhaps something like this would work:
local plr = game.Players:GetPlayerFromCharacter(Human.Parent) if plr:GetRankInGroup(GroupId) >= min and plr:GetRankInGroup(GroupId) <= max or -- etc.
Notice how Human.Parent
is replaced with plr
, allowing you to get the player's rank in the group. Hope this helps :)