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

problem making script that kills on-touch conditionally?

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

1 comment

0

mabye capatilize workspace is line 4? I posted here because i wasn't sure if you would get the notification or not.

1 answer

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

11 comments

0

Thanks for the quick response, but this still doesn't seem to work. I touched the FieldOfDeath when transparency of Shot was 0.9, but it STILL didnt work..

0

mabye capatilize workspace is line 4?

0

Still no errors, but doesn't work.

0

if there are no errors, this means that it simply isn't running some code due to the conditions of the if statment being false.

0

I edited the script to have prints, and i removed some of the conditions on the second if statment. Please tell me what prints in the out put

0

I forgot something, it was 0.1, not 0.9. i changed that and checked every possible little thing, i don't understand, it doesn't work. Oh and one question, this will work with R15, right?

0

Sorry, didnt see your comment where you edited. Ill try that now

0

Ok now i get an error that says FieldOfDeath is not a valid member of DataModel.

0

Yes, this will work with r-15. Make sure your heirachy is right (script.Parent.Parent.Parent.FieldOfDeath).

0

Yeah, i put the script inside of FieldOfDeath and changed it to script.parent to make it easier.

0

Ok so i tried it and i don't get first or second message in the output.

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