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)
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 :)
(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.