Hey, I am currently creating an obby game and am making my first obstacle which has killparts, the script I have tried is below, but it is not working.
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(50) -- change 50 to anything
end
end)
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if hit and humanoid then
humanoid:TakeDamage(50) -- change 50 to anything
end
end)
The humanoid object exists in the player’s character, not the player instance itself.
script.Parent.Touched:Connect(function(hit)
local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
if not Player then return end
local Character = Player.Character
if not Character then return end
local Humanoid = Character:FindFirstChild('Humanoid')
if not Humanoid then return end
Humanoid.Health = 0 -- However, Character:BreakJoints() is more effective.
end)