Woah, that is completely unnecessary and in-efficient. You can as mentioned above loop through all parts.
Not that good of scripting, but I do know this.
After the line: if hit.Parent:FindFirstChild(“Humanoid”) then
link the humanoid to another variable, then declare the “.Health” property to 0
Hope helps
But if there are 27 parts that kill, 27 scripts is inefficient
He could just put them in a folder and duplicate a preexisting one.
i haven’t tested this code, but this hypothetically should work
put all your killbricks in a model
if this works, this script could be anywhere to reference the model and get all bricks inside it to kill. not sure if it works with a folder, you could try.
local killBricks = killbrickmodel
local killBrickchildren = killBricks:GetChildren()
for i = 1, #killBrickChildren do
part = killBrickChildren[i]
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid").Health = 0
end
end)
end
That doesn’t make any sense. You don’t need to have individual script for each part, as this is just redundant. If you want to do that, you just clone the main part.
Something wierd just happened.
If i die now, the camera stays where it was when i died.
What if he wanted to change how kill bricks would work? He would have to go through tons of scripts and change all of them.
Lol i just would love to spend my afternoon changing 27 identical scripts!
You would like to change a ton of scripts?
try this
I know it works for children inside a model, so i assume events like tocuched would work too. as for a folder I’m not sure.
The problem has already been solved, but thank you for your efforts!
Let’s suggest you have a lot of kill bricks and they are in a folder, so you would do:
local KillParts = game.Workspace.KillParts:GetChildren()
for index, killPart in pairs(KillParts:GetChildren()) do
if killPart:IsA("BasePart") then
killPart.Touched:Connect(function(Hit)
if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent:BreakJoints() --This will instantly kill the player, because it will break the joints of the character.
end
end)
end
end
Tbh i would use Collection Service you could ‘Tag’ the bricks and have one central script that defines what happens if you touch a Part with that tag. Would come in handy later down in the line since you don’t want a huuuge folder.
I tested my script for reference and it does work in a model
Watch this video by AlvinBlox about CollectionService which means all parts are affected by one script Collection Service Tutorial - Roblox Scripting - YouTube
to tag parts use this plugin
i can remeber i did something like that in unity, but i didnt know you could tag stuff in roblox.
There is a plugin for that in ROBLOX