Multiple Click detectors

Aight so, i have 4 parts, every part has inside a Click detector

Those 4 ClickDetectors parts are created by a for i,v in iparis() script so i can create how much i need
Also i’ve added a check to player backpack with a tool ("tool)

The problem is that when clicking and using the ClickDetector.MouseClick:Connect(Function)
I don’t have any output

BloodPart = script.Parent.Parent
BloodTypes = require(game.ServerScriptService.Blood)
Blood = {BloodPart.Blood1,BloodPart.Blood2,BloodPart.Blood3,BloodPart.Blood4}

player = game:GetService("Players")

for i,v in ipairs(Blood) do
CDec = Instance.new("ClickDetector")
CDec.Parent = v.Parent
CDec.MaxActivationDistance = 10
wait()
end

CDec.MouseClick:Connect(function(player)

print("Clicked")
local tool = player.Backpack:FindFirstChild("BloodTaker")
print("Clicked2")
end)

I believe you could just move the MouseClick function into the for-loop.

BloodPart = script.Parent.Parent
BloodTypes = require(game.ServerScriptService.Blood)
Blood = {BloodPart.Blood1, BloodPart.Blood2, BloodPart.Blood3, BloodPart.Blood4}

player = game:GetService("Players")

for i, v in ipairs(Blood) do
    CDec = Instance.new("ClickDetector")
    CDec.Parent = v.Parent
    CDec.MaxActivationDistance = 10
    CDec.MouseClick:Connect(function(player)
        print("Clicked")
        local tool = player.Backpack:FindFirstChild("BloodTaker")
        print("Clicked2")
    end)
end
1 Like

This worked! Also i noticed that the ClickDetector Parent wasn’t right so the output wasn’t working, Thank you for helping! :smile:

1 Like