I’m new to coding with Lua and haven’t learned much but I can’t figure out why this script won’t work.
The parent of the script is the NPC model and the script’s function is to kill the NPC when a car hits it.
local npc = script.Parent:FindFirstChild("Torso") -- object going to be hit
local humanoid = script.Parent:FindFirstChild("Humanoid") --Humanoid
function onTouched(hit)
print("HIT! Object being touched:", hit.Name) -- This prints diiferent parts of "classic car" that hit the torso
if hit.parent:Isa("classic car") then--double checking if the object's parent is the model "classic car"
print("CAR HIT!")
humanoid:TakeDamage(100) --Kill NPC when car touches it
end
end
npc.Touched:Connect(onTouched) --When the torso is touched it connects to the function "OnTouched"
Any help would be appreciated!
Also, is it possible to re write the script to where the NPC dies when the car hits it at a certain velocity? Thank you!
Everything is possible if you can think about it. Now I won’t spoonfeed because I don’t know how your game works, but Touched event and If statements are your friends here.