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

problem making script that kills on-touch conditionally?

Asked by
B_Iu 31
7 years ago

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
0
mabye capatilize workspace is line 4? I posted here because i wasn't sure if you would get the notification or not. User#17125 0 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

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.. B_Iu 31 — 7y
0
mabye capatilize workspace is line 4? User#17125 0 — 7y
0
Still no errors, but doesn't work. B_Iu 31 — 7y
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. User#17125 0 — 7y
View all comments (7 more)
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 User#17125 0 — 7y
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? B_Iu 31 — 7y
0
Sorry, didnt see your comment where you edited. Ill try that now B_Iu 31 — 7y
0
Ok now i get an error that says FieldOfDeath is not a valid member of DataModel. B_Iu 31 — 7y
0
Yes, this will work with r-15. Make sure your heirachy is right (script.Parent.Parent.Parent.FieldOfDeath). User#17125 0 — 7y
0
Yeah, i put the script inside of FieldOfDeath and changed it to script.parent to make it easier. B_Iu 31 — 7y
0
Ok so i tried it and i don't get first or second message in the output. B_Iu 31 — 7y
Ad

Answer this question