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

Other multiple methods or advices in making kill bricks scripts?

Asked by 5 years ago

As you can see, kill bricks are scripted and put around Roblox obbies or other games for a while. But I can see most of them react fast. Some are slow. The most common script used is:

local p = script.Parent
p.Touched:Connect(function(part)
    if not part.Parent then return end
    local char = part.Parent
    local hum = char:FindFirstChildOfClass("Humanoid") --Or they use FindFirstChild haha.
    if hum then
        hum.Health = -1
    end
    end
end)

The script above uses the "Touched" event on BaseParts to react on player's interactions. But this could cause a huge amount of memory waste for the server. Even adding a debounce would cause trouble, if you use debounces. Other players could easily get through the brick at the last second without dying after somebody touched it.

The second method I've seen and which is bad is Checking local's character parts. Which is a local script and this can easily be exploited.

Are there any other methods? Advices in improving?

4 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid then
        hit.Parent.Humanoid.Health = 0
    end
end
Ad
Log in to vote
0
Answered by 5 years ago
brick.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then 
        local character = hit.Parent
        character:BreakJoints() --  same thing as humanoid.Health = 0
    end
end
Log in to vote
0
Answered by
jaschutte 324 Moderation Voter
5 years ago

There is a service named CollectionService, it is really usefull and efficient for code which effects multible parts the same way. This is how you use it:

Make a server script in the killing part and put this code in it.

game:GetService("CollectionService"):AddTag(script.Parent, "Kill") --adds a tag to the part.
script:Destroy() --script is no longer needed so might as well destroy it.

Then make a server script in ServerScriptService (or anywhere really) and put this code in it.

for k,v in pairs(game:GetService("CollectionService"):GetTagged("Kill")) do --loop over every part with the 'Kill' tag
    v.Touched:Connect(function(p) --fires when something touched the tagged part
        local humanoid = p.Parent:FindFirstChild("Humanoid")  --find out if 'p' is a player
        if humanoid then
            humanoid.Health = 0 --kill the player
        end
    end)
end
Log in to vote
-2
Answered by
SCP774 191
5 years ago

You can use Region3 for it. For a tutorial, watch this video.

https://www.youtube.com/watch?v=qOhZi1jUEvI

0
Not areas, he want's "Bricks"that kill players. mixgingengerina10 223 — 5y
0
That answer is completely incorrect. What would you expect from checking frequently Region3? Just creating waste of memory. I can see that you didn't read the post carefully. magicguy78942 238 — 5y

Answer this question