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

how do I make it so that if the part is Neon, it kills you?

Asked by 4 years ago

i've tried to make a script that when the part is neon, it will break the joints of the player. i put this script in the part and every 5 seconds it changes from neon to smooth plastic and this works.

while true do wait(5) script.Parent.Material = Enum.Material.Neon if script.Parent.Material == Enum.Material.Neon == true then wait(5) script.Parent.Material = Enum.Material.SmoothPlastic end

but when i put this script in, the block just stays neon and doesn't kill me.

while true do
    wait(5)
    script.Parent.Material = Enum.Material.Neon
    if script.Parent.Material == Enum.Material.Neon == true then
        wait(5)
        script.Parent.Material = Enum.Material.SmoothPlastic
        if script.Parent.Material == Enum.Material.Neon == true then
            script.Parent.Touched:Connect(function(hit)
                if hit.Parent:FindFirstChild ("Humanoid") then
                    hit.Parent:BreakJoints()
                end
            end)

        end
    end

any solutions to this? thanks

2 answers

Log in to vote
1
Answered by 4 years ago

The problem is your if statements. The first if statement will always be true, so it's unnecessary. The second if statement will always be false since it's not == neon. Also don't do Material == Neon == true otherwise it will give you a syntax error. Here's how I'll solve your code (comments included):

--You do not need a while loop for an event. Roblox listens for the event whenever someone touches it.
local debounce = false --I realised you added wait. So this will be your cooldown.
script.Parent.Touched:Connect(function(hit)
    --Those if statements are unnecessary unless if you're adding a debounce (or cooldown), which is recommended.
    if not debounce then --alternative: if debounce == false then
        debounce = true
        script.Parent.Material = Enum.Material.SmoothPlastic
        if hit.Parent:FindFirstChild("Humanoid") then
            hit.Parent:BreakJoints()
        end
        wait(5) --Change this whatever you want. I'll just stick with 5.
        script.Parent.Material = Enum.Material.Neon
        debounce = false
    end
end)
0
thanks a lot man, i'm a very new scripter so this help is very appreciated notoriousNoah10 5 — 4y
0
@notoriousNoah10 if this answered your question, please accept the answer. Optikk 499 — 4y
0
actually no thats not it. i wanted it so that if the block is every 5 seconds it changes from smoothplastic to neon, and if you touch it while its neon then you die notoriousNoah10 5 — 4y
Ad
Log in to vote
0
Answered by
iiii676 23
4 years ago

You don't need the

== true

in your script.

Answer this question