I want to kill the players with the name "Noob" when someone touches a brick but I don't know how to do that in my code
local noobs = workspace:GetChildren() function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then for i,v in pairs(noobs) do if v.Name == "Noob" then end end wait(0) end end script.Parent.Touched:connect(onTouched)
You can use the BreakJoints
function to kill character models :)
Note: to get live results whenever the part is touched, you have to define 'noobs' inside the onTouched function
function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") local noobs = workspace:GetChildren() --Define inside if h then for i,v in pairs(noobs) do if v.Name == "Noob" and v.Humanoid.Health ~= 0 then v:BreakJoints() --BreakJoints function end end wait() end end script.Parent.Touched:connect(onTouched)
local noobs = workspace:GetChildren() function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h and h~=nil then for i,v in pairs(noobs) do if v.Name == "Noob" then if v:FindFirstChild("Humanoid") then v.Health = 0 end end end end end script.Parent.Touched:connect(onTouched)
local noobs = workspace:GetChildren() function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then for i,v in pairs(noobs) do if v.Name == "Noob" then end end wait(0) end end script.Parent.Touched:connect(onTouched)
Not sure why you want to do this, but you can use Humanoid:TakeDamage(x)
to directly remove x HP from the player. Like this:
local noobs = workspace:GetChildren() function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then for i,v in pairs(noobs) do if v.Name == "Noob" then v.Humanoid:TakeDamage(1000000000000000) end end wait(0) end end script.Parent.Touched:connect(onTouched)
I found my way of going about this more efficient. For this to work put the script into the part.
local part = script.Parent part.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then -- Checks if a player hit it for i,v in ipairs(game.Players:GetPlayers()) do -- Loops through all players if v.Name == "Noob" then -- If their name is "Noob" v.Character:BreakJoints() -- Kill them by breaking joints end end end end))