Hello, I wanted to make a part kill only the players, but it also kills the models with a humanoid inside, how do i fix this?
The script: (I’m a bad scripter)
function onTouch(part)
local humanoid = game.Players.PlayerAdded:FindFirstChild("Humanoid")
if (humanoid ~= nil) then
humanoid.Health = humanoid.Health - 10
end
end
script.Parent.Touched:connect(onTouch)
function onTouch(part)
if part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(part.Parent) then
part.Parent.Humanoid:TakeDamage(10)
end
end
function onTouch(part)
if part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(part.Parent) then
part.Parent.Humanoid:TakeDamage(10)
end
end
script.Parent.Touched:Connect(onTouch)
This one will always have it occur after 2 seconds, even if the player stops touching the part:
function onTouch(part)
task.wait(2) -- Doesn't matter if you use task.wait or wait.
if part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(part.Parent) then
part.Parent.Humanoid:TakeDamage(10)
end
end
script.Parent.Touched:Connect(onTouch)