#kill script
1 messages · Page 1 of 1 (latest)
Using :GetChildren() on the model (if the script was inside it, you'd probably do script.Parent:GetChildren()) and loop through every child, connect to their .Touched events, make sure the part that touched the kill part is actually from a player's character via the Player's service Players:GetPlayerFromCharacter(touchedPart.Parent) and if it is, get their character's humanoid, and set their health to 0
this?
-- Place this script inside the model that holds all the parts you want to use
local Players = game:GetService("Players")
-- Loop through all children of the model
for _, part in pairs(script.Parent:GetChildren()) do
if part:IsA("BasePart") then -- Make sure it's a part
-- Connect to the Touched event for each part
part.Touched:Connect(function(hit)
-- Check if the part that touched the model is part of a player's character
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
-- Get the Humanoid of the player's character
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
-- Set the player's health to 0 (kill the player)
humanoid.Health = 0
end
end
end)
end
end
Did you give it a go?
but it also looks like someone else made this or you AI generated it
my friend sent me it
** You are now Level 4! **
Okay that's weird. Never had to debug through someone before. Feels silly.
If it didn't work, why don't you ask your friend?
because he told me to tell him how and he does it
idk why
but he better not be using AI or he gonna mess my game up
AI messes your game up never use it
Well that's your business.
You need to tell me in what way it doesn't work. Give me more details. Errors? Warnings? Does it not kill at all?
it doesnt kill at all
Okay, can you show me where you placed the script in the explorer?
i wanna make it so that if you touch any of him you die
I didn't realize it was a model with models. That makes things different. You have to go into every model and get that model's children too.
Oh no wait sorry. GetDescendants instead of GetChildren
local Players = game:GetService("Players")
for _, part in pairs(script.Parent:GetDescendants()) do
if part:IsA("BasePart") then
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end)
end
end
my friend sent me this now
is he corr3ect?
oh its correct
yay
but theres a problem
and that is?
it kills me multiple tiems and makes the guh noise multiple times and glicthes my camera
when i die
not forever tho when i respawn it stops
Just check to make sure the humanoid's health isn't already 0
wait idek if i have a health bar
Why does that matter?
Like humanoid.Health > 0 as a part of the if statment. So make sure there is a humanoid and that it isn't already dead
Mark the post as solved by adding the solved tag 🙂