I’m currently in the process of making a few obstacles for my game.
I’m making one of those killbrick jump things but the killbricks are not working.
this is my code:
local KillParts = script.Parent.KillParts.KillPart
KillParts.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid").Health = 0
end
end)
:GetChildren() returns a table, not a BasePart. Instead, you would do:
local KillParts = script.Parent.KillParts:GetChildren()
for _, killPart in ipairs(KillParts) do
if v:IsA("BasePart") then
killPart.Touched:Connect(function(hit)
-- script
end)
end
end
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.
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