Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this Brick not kill me when I click on it?

i was trying to make a Obby, and i made a part where if you would click on it it would not kill you

i'm not really sure what to do at this point as i'm very new to scripting. Heres the code: --// Variables local Part = game.Workspace.PURPLE local Click = game.Workspace.Click

Part.Transparency = 0 Part.CanCollide = true

game.Workspace.PURPLE.ClickDetector.MouseClick:Connect(function(hit) pcall(function() Part.Transparency = 0.6 Part.CanCollide = false Click:Play() hit.Parent.Humanoid:TakeDamage(0) wait(3) hit.Parent.Humanoid:TakeDamage(100) Part.Transparency = 0 Part.CanCollide = true end) end)

i'm not 100% sure what pcall does, but it did work with the damage.

(don't mind the name of the brick lol)

4 comments

0

Please place all your code in a code block. Thanks.

0

he needs to take 100 damage to die

0

if you dont want the player to die then why are u posting here

0

just dont make the humanoid take damage??

2 answers

✓ Accepted answer

Pcall is a meathod of handling errors in lua I'm not going to in depth but here is a link to a page explaining it Link

Assuming that "PurpleBrick" is the part you want the user to click and that it is parented by workspace. And that "PurpleBrick" has a Click Detector

local partToClick = game.Workspace.PurpleBrick
local damage = true

local player = game.Players.LocalPlayer

partToClick.ClickDetector.MouseClick:Connect(function()
	damage = false
end)

for i = 0, 3, 1 do
	if damage and i == 3 then
		player.Character.Humanoid:TakeDamage(100)
	end
	wait(1)
end

The above code will give the player 3 seconds to click on the button or face demise.

If you wanted to make it so the player has 3 seconds from the first time they click the button to click the button again, then you would use this code

local partToClick = game.Workspace.PurpleBrick
local damage = true

local player = game.Players.LocalPlayer

local firstClick = true

partToClick.ClickDetector.MouseClick:Connect(function()
	
	if firstClick then
		firstClick = false
		
		for i = 0, 3, 1 do
			if damage and i == 3 then
				player.Character.Humanoid:TakeDamage(100)
			end
			wait(1)
		end
		
	else
		damage = false
	end
	
end)

Feel free to dm me if you have more questions (I might not respond til after school)

Code is tested and working

If this answer helped you please accept it :)

3 comments

0

only use wait(3) or delay(3, function()

0

Please friend me @kaidenhoward I need help with the brick and can't massage you for some odd reason.

0

@tehpwnzer3 i sent a freind request

(This is mainly for future people that answer this) I believe what is going on is that the person wants it so that if the player DOESN'T click on the brick they'll take damage, but if they DO click on it they do not take the damage. It's either this or vice versa.

This discussion is preserved as it was. New answers, comments, and votes are closed.