Why Does My clickdetector script not work

I Click the click detector of the baseplate and if the stringValue named “Health” Reaches the value Of 0 The Baseplate Gets Transparent And CanCollide off but the script doesn’t work:

clicky = script.Parent
plate = clicky.Parent
plateHealth = plate.Health

clicky.MouseClick:Connect(function(Clicker)
	if Clicker then
		plateHealth.Value = plateHealth.Value - 5
		if plateHealth.Value == 0 then
			plate.Transparency = 1
			plate.CanCollide = false
			clicky:Destroy()
		end
	end
end)
4 Likes
if Clicker then

Clicker does not exist and is set to nil, remove the line and the script should work

1 Like

and is it possible to make the minimum value for the stringValue?

change the health value to a numbervalue instead of a stringvalue

3 Likes
clicky = script.Parent
plate = clicky.Parent
plateHealth = plate.Health

clicky.MouseClick:Connect(function(Clicker)
	plateHealth.Value = plateHealth.Value - 5
	if plateHealth.Value <= 0 then
		plate.Transparency = 1
		plate.CanCollide = false
		clicky:Destroy()
	end
end)

here is the script, eveything should work. be sure to change the health value to a numbervalue instead

3 Likes

Clicker is the player clicking but yeah ur right it isn’t necessary

1 Like

Is this a local script or server script (it wouldn’t work as a local script)
Also is plate a humanoid or a value bc if it is humanoid you dont need the .value at the end of plateHealth

Nevermind :+1:

Thanks For the help man ! :slight_smile:
i appreciate you

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