part = game.Workspace.Part
game.Workspace:findFirstChild("ReportingDosntWork") part.Position = Vector3.new(-6,1000,-11)
function onTouched(part) game.Workspace.ReportingDosntWork.Humaniod.Health = 0 end
part.Touched:Connect(onTouched)
When I use this script, it kills me even when i don't touch it. Can somebody help?
For your script, whenever part is touched it kills you. That means if it's touched by another part it will kill you, for exmaple if it touches the baseplate, you're a dead boi
part = game.Workspace.Part function onTouched(part) if part.Parent.Name == 'ReportingDosntWork' then part.Parent.Humanoid.Health = 0 end end part.Touched:Connect(onTouched)
While Icy_Qube's solution works in most cases, but in some circumstances it doesn't work.
A general issue with checking if part.Parent.Name == "ReportingDosntWork"
is that it doesn't know if it is a player or an NPC, or anything else that is named "ReportingDosntWork".
So, to make this work efficiently, you need to use the :GetPlayerFromCharacter
function, which gets a player object from a character. The reason we use this is that all body parts are descendants of the character.
part = game.Workspace.Part function onTouched(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then hit.Parent.Humanoid.Health = 0 end end part.Touched:Connect(onTouched)
Put this in the part you wish
local Brick = script.Parent local function PlayerTouched(Part) local Parent = Part.Parent if game.Players:GetPlayerFromCharacter(Parent) then Parent.Humanoid.Health = 0 end end Brick.Touched:connect(PlayerTouched)
You can also change how much damage you want