Is there a way to make local click detectors work?

I am trying to make a skill tree script and I am spawning the skill tree locally and adding click detector to make it possible to interact with the skill tree.

Unfortunately the click detectors don’t work, the cursor changes but the connections does not fire when clicking it. Is there a way to make a local ClickDetector work? I’d prefer to keep it all in a local script if possible

-- Add click detectors
tree_node.CanCollide = true
local click_detector = Instance.new("ClickDetector")
click_detector.MaxActivationDistance = math.huge
click_detector.MouseClick:Connect(function()
	camera.CFrame = tree_node.CFrame * CFrame.new(0, -15, 0) * CFrame.Angles(math.rad(90), 0, 0)
end)
click_detector.Parent = tree_node
6 Likes

no, you will have to send an event to the server to create a click detector

2 Likes

My skill trees are made of parts, so I’ll have to create the whole skill tree on the server? Is there a workaround that I could use to still create them on the client?

2 Likes

you can make a server script and store a table for each player inside a table
e.g

local players = {
someguy = {thisupgrade = true; anotherupgrade = false;}
;}

2 Likes

Are you sure the MouseClick event does not fire? If the CameraType is not set to Scriptable, the default camera module will update the camera CFrame back to the character, which might be the reason why you don’t see any results.

When you want to move the camera to a specific spot, set CameraType to Scriptable, and then set the CFrame, and when you want it to go back to the character set the type to Custom, which would let the camera module to control the camera again.

1 Like

That’s what I’m currently doing, but to make an interactable skill tree for the player I am creating parts and tweening the camera to them, I will provide more context in a second, I am doing something rn

1 Like

This is a snippet from my code with some unecessary stuff removed:

-- Get object
local skill_tree_obj = skill_trees:FindFirstChild(skill_tree_name)
if skill_tree_obj == nil then
	return
end

-- Create skill tree
-- Background
local bg = skill_tree_bg:Clone()
skill_tree_bg:PivotTo(CFrame.new(100000, -100000, 100000))
skill_tree_bg.Parent = debris_folder

-- Skill tree
skill_tree_obj = skill_tree_obj:Clone()
skill_tree_obj:PivotTo(skill_tree_bg.PrimaryPart.CFrame)
skill_tree_obj.Parent = debris_folder

-- Get camera
local camera = workspace.Camera
camera.CameraType= Enum.CameraType.Scriptable

-- Fill out skill tree
for index, skill in ipairs(skill_tree_obj:GetChildren()) do
	-- Verify if it's a node obj
	if skill:IsA("BasePart") == false or skill:FindFirstChild("Cost") == nil or skill:FindFirstChild("Requirement") == nil or skill:FindFirstChild("Unlocked") == nil then
		continue
	end

	-- Add click detectors
	skill.CanCollide = true
	local click_detector = Instance.new("ClickDetector")
	click_detector.MaxActivationDistance = math.huge
	click_detector.MouseClick:Connect(function()
		camera.CFrame = skill.CFrame * CFrame.new(0, -15, 0) * CFrame.Angles(math.rad(90), 0, 0)
	end)
	click_detector.Parent = skill
end

-- Point camera
camera.CFrame = skill_tree_obj.PrimaryPart.CFrame * CFrame.new(0, -15, 0) * CFrame.Angles(math.rad(90), 0, 0)

This is what it looks like in game:
https://streamable.com/4740y1

This is the structure:
image

1 Like

I tried playing around a little bit and put this in a Script in ServerScriptService:

wait(10)
local part = Instance.new("Part")
part.CFrame = game.Players.mayoozzzz.Character.PrimaryPart.CFrame
part.Anchored = true
part.Parent = workspace

local click = Instance.new("ClickDetector")
click.MaxActivationDistance = math.huge
click.MouseClick:Connect(function()
	print("lol")
end)
click.Parent = part

and the click detector isn’t firing the MouseClick event either, am I doing something wrong?
The cursor changes when I’m hovering over it but clicking does not work.

1 Like

I found the issue. It’s because of UserInputService, I had a bind on MouseButton1 and whenever it’s binded all ClickDetectors don’t work. In order to fix that I have to unbind my MouseButton1 Action and bind it back later.

I decided it’d better to move my MouseButton1 bind to ContextActionService and it works flawlessly.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.