I am trying to set the permission policy of a 3d Drag detector to a team however upon changing teams it knows that I’ve changed but it wouldn’t allow me to actually drag the physical object after it
local REQUIRED_TEAM = "TeamA"
local ScriptableFolder = workspace:WaitForChild("Scriptable")
local SpotLightFolder = ScriptableFolder:WaitForChild("WatchTower_SpotLights")
local function setupDragDetector(detector)
if not detector:IsA("DragDetector") then return end
local mainPart = detector.Parent
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
detector:SetPermissionPolicyFunction(function(player)
local teamName = player.Team and player.Team.Name
if teamName == REQUIRED_TEAM then
return true
end
return false
end)
end
for _, obj in ipairs(SpotLightFolder:GetDescendants()) do
setupDragDetector(obj)
end
SpotLightFolder.DescendantAdded:Connect(setupDragDetector)
Yes, thank you. The permission policy was needed to be set on the server then you pass the team name through an event from the client to the server to update it. I’ve put the scripts below just in case someone else runs into the same issue as me.
local
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local updatePermissionEvent = replicatedStorage:WaitForChild("UpdatePermissions")
local function onTeamChange(newTeam)
if not newTeam then return end
if newTeam.Name == "TeamA" then
print("Allowed — notifying server to update permissions.")
updatePermissionEvent:FireServer(newTeam)
else
print("Not allowed.")
updatePermissionEvent:FireServer(newTeam)
end
end
if localPlayer.Team then
onTeamChange(localPlayer.Team)
end
localPlayer:GetPropertyChangedSignal("Team"):Connect(function()
print(localPlayer.Team)
onTeamChange(localPlayer.Team)
end)
Server
local replicatedStorage = game:GetService("ReplicatedStorage")
local updatePermissionEvent = replicatedStorage:WaitForChild("UpdatePermissions")
local ScriptableFolder = workspace:WaitForChild("Scriptable")
local SpotLightFolder = ScriptableFolder:WaitForChild("WatchTower_SpotLights")
local function setupDragDetector(detector, team)
if not detector:IsA("DragDetector") then
return
end
detector:SetPermissionPolicyFunction(function(player)
print("Checking team:", team)
if team.Name == "TeamA" then
print("Allowed")
return true
end
print("Denied")
return false
end)
end
local function updatePermissions(team)
for _, obj in ipairs(SpotLightFolder:GetDescendants()) do
setupDragDetector(obj, team)
end
end
updatePermissionEvent.OnServerEvent:Connect(function(player, newteam)
print("Received update permissions event: " .. newteam.Name)
updatePermissions(newteam)
end)