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