Is there a way to make clickdetector’s MaxActivationDistance depend on the distance of the player’s camera instead of the distance of it’s character?
ClickDetectors are kind of outdated, for more functionality you should implement this yourself via client and server logic communicating with remotes.
You use ProximityPrompt
for this,
But here is an Example for a MaxActivationDistance
on a ClickDetector:
local CD = script.Parent.ClickDetector
local MaxDistance = 10 -- Max Distance for the Click
CD.MouseClick:Connect(function(p) -- The Variable on the Player who clicked it
local Mag = (p.Character.PrimaryPart.Position - CD.Parent.Position).Magnitude
-- Distance of the Player from the Part
if Mag > MaxDistance then
-- code for if the Player isnt close
else
-- code for if the Player is close
end
end)
You dont need to get the magnitude from the primary part position to the clickdetector’s parent position, you can just do
local distance = plr:DistanceFromCharacter(CD.Parent)
if distance > maxDistance then
-- stuff
end
Thank you guys, hope it helps. Im gonna test it out soon