Hey, so I have a morph GUI yet when I made it so it can support 2 groups, the main and a sub under 1 profile.
The issue I am having is that I still shows up the morph from the other group when the player isn’t in it.
Help is appreciated.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local RankRestrictedMorphs = {}
RankRestrictedMorphs.Disabled = false
function RankRestrictedMorphs.CanWearMorph(...)
local args = { ... }
local player
local morphFolder
if RunService:IsServer() then
player = args[1]
morphFolder = args[2]
else
player = Players.LocalPlayer
morphFolder = args[1]
end
if not player or not morphFolder then
return true
end
local groupId = morphFolder.Parent:GetAttribute("GroupId")
local groupId2 = morphFolder.Parent:GetAttribute("GroupId2")
if groupId then
local isInGroup = player:IsInGroup(groupId)
if not isInGroup then
return false, "You are not in the group!"
end
local rankValue = morphFolder:GetAttribute("Rank")
local onlyrankValue = morphFolder:GetAttribute("OnlyRank")
if rankValue then
local rankNumber = player:GetRankInGroup(groupId)
if rankNumber < rankValue then
return false, "You do not have the required rank!"
end
end
if onlyrankValue then
local rankNumber = player:GetRankInGroup(groupId)
if not (rankNumber == onlyrankValue) then
return false, "You do not have the required rank!"
end
end
elseif groupId2 then --Where I think the issue would be.
local isInGroup2 = player:IsInGroup(groupId2)
if not isInGroup2 then
return false, "You are not in the group!"
end
local rankValue2 = morphFolder:GetAttribute("Rank2")
local onlyrankValue = morphFolder:GetAttribute("OnlyRank")
if rankValue2 then
local rankNumber2 = player:GetRankInGroup(groupId2)
if rankNumber2 < rankValue2 then
return false, "You do not have the required rank!"
end
end
if onlyrankValue then
local onlyrankNumber = player:GetRankInGroup(groupId)
if not (onlyrankNumber == onlyrankValue) then
return false, "You do not have the required rank!"
end
end
end
return true
end
return RankRestrictedMorphs```
Is this not supposed to return false? I assume based on the function name that its checking if the player DOES have access, rather then checking if they DONT have access, so I would assume that if the player is nil or their “morphFolder” is nil then it should return false.
the elseif groupid2 should be chnged to just if groupid2 will check for both groups and use onlyrank2 instead of onlyrank
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local RankRestrictedMorphs = {}
RankRestrictedMorphs.Disabled = false
function RankRestrictedMorphs.CanWearMorph(...)
local args = { ... }
local player
local morphFolder
if RunService:IsServer() then
player = args[1]
morphFolder = args[2]
else
player = Players.LocalPlayer
morphFolder = args[1]
end
if not player or not morphFolder then
return true
end
local groupId = morphFolder.Parent:GetAttribute("GroupId")
local groupId2 = morphFolder.Parent:GetAttribute("GroupId2")
if groupId then
local isInGroup = player:IsInGroup(groupId)
if not isInGroup then
return false, "You are not in the group!"
end
local rankValue = morphFolder:GetAttribute("Rank")
local onlyrankValue = morphFolder:GetAttribute("OnlyRank")
if rankValue then
local rankNumber = player:GetRankInGroup(groupId)
if rankNumber < rankValue then
return false, "You do not have the required rank!"
end
end
if onlyrankValue then
local rankNumber = player:GetRankInGroup(groupId)
if not (rankNumber == onlyrankValue) then
return false, "You do not have the required rank!"
end
end
end
if groupId2 then
local isInGroup2 = player:IsInGroup(groupId2)
if not isInGroup2 then
return false, "You are not in the group!"
end
local rankValue2 = morphFolder:GetAttribute("Rank2")
local onlyrankValue2 = morphFolder:GetAttribute("OnlyRank2")
if rankValue2 then
local rankNumber2 = player:GetRankInGroup(groupId2)
if rankNumber2 < rankValue2 then
return false, "You do not have the required rank!"
end
end
if onlyrankValue2 then
local rankNumber2 = player:GetRankInGroup(groupId2)
if not (rankNumber2 == onlyrankValue2) then
return false, "You do not have the required rank!"
end
end
end
return true
end
return RankRestrictedMorphs
It looks like your logic for checking the second group might be causing the issue. Specifically, in the else condition for groupId2, you’re not checking the OnlyRank value correctly.
You should use the onlyrankValue2 variable instead of onlyrankValue, which is referencing the first group. Here’s how you can modify that section:
Make sure that you’re correctly setting the OnlyRank attribute for both groups in the morph folder as well. This adjustment should help ensure that players can only wear morphs from the group they belong to.
My problem isn’t with the OnlyRank, yet it is with checking the 2nd groupId. I want it to run through both groupIds and checks their rank, if the player isn’t in the 2nd groupId I wish for it to ignore that part.
This doesn’t work because I don’t wish for it to check if the player is in both groups, yet I wish for it to check each group for their rank. The way my morph system would work would for it to check through both groups, if the player is in 1 of the groups and not the other the morph would show up only for that group, if the player is in both it would show up the morphs for both groups.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local RankRestrictedMorphs = {}
RankRestrictedMorphs.Disabled = false
function RankRestrictedMorphs.CanWearMorph(...)
local args = { ... }
local player
local morphFolder
if RunService:IsServer() then
player = args[1]
morphFolder = args[2]
else
player = Players.LocalPlayer
morphFolder = args[1]
end
if not player or not morphFolder then
return true
end
local groupId = morphFolder.Parent:GetAttribute("GroupId")
local groupId2 = morphFolder.Parent:GetAttribute("GroupId2")
local canWear = false
if groupId then
local isInGroup = player:IsInGroup(groupId)
if isInGroup then
local rankValue = morphFolder:GetAttribute("Rank")
local onlyrankValue = morphFolder:GetAttribute("OnlyRank")
local rankNumber = player:GetRankInGroup(groupId)
if (not rankValue or rankNumber >= rankValue) and
(not onlyrankValue or rankNumber == onlyrankValue) then
canWear = true
end
end
end
if groupId2 and not canWear then
local isInGroup2 = player:IsInGroup(groupId2)
if isInGroup2 then
local rankValue2 = morphFolder:GetAttribute("Rank2")
local onlyrankValue2 = morphFolder:GetAttribute("OnlyRank2")
local rankNumber2 = player:GetRankInGroup(groupId2)
if (not rankValue2 or rankNumber2 >= rankValue2) and
(not onlyrankValue2 or rankNumber2 == onlyrankValue2) then
canWear = true
end
end
end
if not canWear then
return false, "You do not have the required rank or group membership!"
end
return true
end
return RankRestrictedMorphs
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local RankRestrictedMorphs = {}
RankRestrictedMorphs.Disabled = false
function RankRestrictedMorphs.CanWearMorph(...)
local args = { ... }
local player
local morphFolder
if RunService:IsServer() then
player = args[1]
morphFolder = args[2]
else
player = Players.LocalPlayer
morphFolder = args[1]
end
if not player or not morphFolder then
return true
end
local groupId = morphFolder.Parent:GetAttribute("GroupId")
local groupId2 = morphFolder.Parent:GetAttribute("GroupId2")
local function checkGroup(gId, rankAttr, onlyRankAttr)
if not gId then return false end
local isInGroup = player:IsInGroup(gId)
if not isInGroup then return false end
local rankValue = morphFolder:GetAttribute(rankAttr)
local onlyrankValue = morphFolder:GetAttribute(onlyRankAttr)
local rankNumber = player:GetRankInGroup(gId)
if rankValue and rankNumber < rankValue then
return false
end
if onlyrankValue and rankNumber ~= onlyrankValue then
return false
end
return true
end
local canWearGroup1 = checkGroup(groupId, "Rank", "OnlyRank")
local canWearGroup2 = checkGroup(groupId2, "Rank2", "OnlyRank2")
return canWearGroup1 or canWearGroup2, "You do not have the required rank or group membership!"
end
return RankRestrictedMorphs