Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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)

0
Please place all your code in a code block. Thanks. OptimisticSide 199 — 5y
0
he needs to take 100 damage to die WideSteal321 773 — 5y
0
if you dont want the player to die then why are u posting here Gey4Jesus69 2705 — 5y
0
just dont make the humanoid take damage?? GoldAngelInDisguise 297 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
only use wait(3) or delay(3, function() yHasteeD 1819 — 5y
0
Please friend me @kaidenhoward I need help with the brick and can't massage you for some odd reason. tehpwnzer3 2 — 5y
0
@tehpwnzer3 i sent a freind request TheMysticLynxx 89 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question