Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make efficient damage bricks using only one script?

Asked by 4 years ago

I've made a damage script for the kill parts in my obby,

function onTouched(hit)
        local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
                human.Health = 0
        end
end
script.Parent.Touched:connect(onTouched)

but I want to eliminate most of these scripts to make sure that my obby runs as fast as possible.

Is there a way to make one script that detects when any of the kill parts (they are all grouped) are touched and then deal 100 damage to the humanoid that touched it?

I've tried putting all of the parts as children under the script and changed the script to say:

function onTouched(hit)
        local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
                human.Health = 0
        end
end
script.Child.Touched:connect(onTouched)

but that didn't seem to work.

0
ik this is probably a noob question, but i kinda new to programming sergeant_ranger 184 — 4y
0
I don't think you are able to do that. An idea is to copy and paste the script on each brick. luluziluplayzROBLOX 61 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local DamageParts = workspace.Parts:GetChildren()

local function DealDamage(Touched)
    local Humanoid = Touched.Parent:FindFirstChildOfClass("Humanoid")
    if (Humanoid) then
        Humanoid:TakeDamage(Humanoid.Health*Humanoid.MaxHealth)
    end
end

for _,Part in pairs(DamageParts) do
    if (Part:IsA("BasePart")) then
        Part.Touched:Connect(DealDamage)
    end
end
0
how would i make it so that its only the kill parts that are dealing damage, not every single part in the workspace with this script? sergeant_ranger 184 — 4y
0
It wont. Simply just name the Grouped Model "Parts" and the code will do everything from there. Ziffixture 6913 — 4y
0
thx i modded the script now and it works perfectly :D sergeant_ranger 184 — 4y
Ad

Answer this question