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

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

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

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)

3 comments

0

thanks a lot man, i'm a very new scripter so this help is very appreciated

0

@notoriousNoah10 if this answered your question, please accept the answer.

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

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