Click to reset script not working

tried to convert a touch killbrick to a click killbrick, doesnt really work

--Variables--
local Brick = script.Parent.Parent
local clickdetector = script.Parent
--End--

--Code--
local function Playerclicked(Part)
	local Parent = Part.Parent.Parent	
	if game.Players:GetPlayerFromCharacter(Parent) then
		Parent.Humanoid.Health = 0
	end
end

Brick.ClickDetector.MouseClick:connect(Playerclicked)

locations:
image

local Click = script.Parent
local Brick = Click.Parent

local function PlayerClicked(Player)
	Player.Character.Humanoid.Health = 0
end

Click.MouseClick:Connect(PlayerClicked)

The “MouseClick” event of a “ClickDetector” instance passes the player instance which clicked it as an argument to any callback function connected to it via the connection instance method “:Connect()”.

1 Like

.MouseCLick returns the player that clicked the clickdetector,
your Parent variable gets the parent of the parent of the player(nothing i guess)

Here’s a reproduction of your script that should work

local function Playerclicked(Player)
	local Hum = Player.Character:FindFirstChild("Humanoid")
        if Hum then
            Hum.Health = 0
        end
end

Brick.ClickDetector.MouseClick:connect(Playerclicked)
1 Like