Text = "Test" script.Parent.Touched:connect(function(Player) local hum = Player.Parent:FindFirstChild("Humanoid") hum.Health = 0 print(Text) end)
Text = "Test" script.Parent.Touched:connect(function(Player) local hum = Player.Parent:FindFirstChild("Humanoid") if hum then hum.Health = 0 end print(Text) end)
You were using FindFirstChild wrong. You had the right idea though. But you weren't checking if it found the humanoid you were just searching for it and regardless of the result you used it in the script.
FindFirstChild returns nil if it can't find the child you're looking for, otherwise it returns the child
An easier way to do this too is by making a WaitForChild.
Text = "Test" script.Parent.Touched:connect(function(hit) local hum = hit.Parent:WaitForChild("Humanoid") if hum then hum.Health = 0 print(Text) end end)
Unlike FindFirstChild, this will wait for the child to exist, then set "hum" as the player's humanoid.