Hey! So, I have a chat command (!togglewalls), which should toggle the nearest tryout pad (union part), if the player is close enough to one of them, and if they have certain ranks in a specific group.
It mostly seems to work, the tryouts pads do toggle on and off, if I’m close enough. However, there is one small issue. It always toggles the tryout pad #2 for some reason. It might be a problem with the checkPermissionAbility() function, though, I’m not sure how to fix it.
ServerScript
local TryoutPads = game.Workspace:WaitForChild("TryoutPads")
local GroupIDs = {14797041, 15328639, 15326631, 15326530, 15328073, 15328147, 15328109, 15328173}
local GroupRanks = {248, 5, 4, 6, 4, 5, 5, 2}
local function checkPermissionAbility(Player)
if Player:IsInGroup(GroupIDs[1]) and Player:GetRankInGroup(GroupIDs[1]) >= GroupRanks[1] then
return true
elseif Player:IsInGroup(GroupIDs[2]) and Player:GetRankInGroup(GroupIDs[2]) >= GroupRanks[2] then
return true
elseif Player:IsInGroup(GroupIDs[3]) and Player:GetRankInGroup(GroupIDs[3]) >= GroupRanks[3] then
return true
elseif Player:IsInGroup(GroupIDs[4]) and Player:GetRankInGroup(GroupIDs[4]) >= GroupRanks[4] then
return true
elseif Player:IsInGroup(GroupIDs[5]) and Player:GetRankInGroup(GroupIDs[5]) >= GroupRanks[5] then
return true
elseif Player:IsInGroup(GroupIDs[6]) and Player:GetRankInGroup(GroupIDs[6]) >= GroupRanks[6] then
return true
elseif Player:IsInGroup(GroupIDs[7]) and Player:GetRankInGroup(GroupIDs[7]) >= GroupRanks[7] then
return true
elseif Player:IsInGroup(GroupIDs[8]) and Player:GetRankInGroup(GroupIDs[8]) >= GroupRanks[8] then
return true
else
return false
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.Changed:Connect(function(Prop)
if Prop == "Character" then
repeat wait(.1) until Player.Character
local Character = Player.Character
if checkPermissionAbility(Player) == true then
Player.Chatted:Connect(function(Message)
local Words = string.split(Message, " ")
if Words[1] == "!togglewalls" then
local Closest
local PlayerPosition = Character.PrimaryPart.Position
if unpack(TryoutPads:GetChildren()) ~= nil then
for i,v in pairs(TryoutPads:GetChildren()) do
if Closest == nil then
Closest = v
else
if (PlayerPosition - v.Position).magnitude < (Closest.Position - PlayerPosition).magnitude then
Closest = v
end
end
end
end
if Closest ~= nil then
for i,v in pairs(TryoutPads:GetChildren()) do
if v == Closest then
if (PlayerPosition - v.Position).Magnitude <= 50 then
if v.Transparency == 1 then
for i = 1,0,-0.1 do
wait(0.02)
v.Transparency = i
end
v.Transparency = 0
v.CanCollide = true
v.CanTouch = true
elseif v.Transparency == 0 then
for i = 0,1,0.1 do
wait(0.02)
v.Transparency = i
end
v.Transparency = 1
v.CanCollide = false
v.CanTouch = false
end
end
end
end
end
end
end)
elseif checkPermissionAbility(Player) == false then
print("You are not allowed to use this command!")
end
end
end)
end)
