Hi. I am having trouble scripting my game, and im trying to make a conditional kill script that is called on-touch of an object when the transparency of "Shot" is 0.9. I have this script currently, and it doesnt work...
if game.workspace.Shot.Transparency == 0.9 then script.Parent.Parent.Parent.FieldOfDeath.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid.Health = 0 end end) end
The problem is, your script wont loop. Basically what is happening is that the script runs, its looks at the if statement, determines it's false, then gets to the end of the script and never runs the script's code ever again. Re order that if state ment, like so
script.Parent.Parent.Parent.FieldOfDeath.Touched:connect(function(hit) if game.workspace.Shot.Transparency == 0.9 then print("first stage works") if hit.Parent:FindFirstChild("Humanoid") then print("second stage works") hit.Parent.Humanoid.Health = 0 end end end)
Now, the script will check if shot has 0.9 transparency EVERY time feild of death gets bumped, and it will only run the death code if shot has transparency 0.9