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

Death wall that kills you is to laggy? Help.

Asked by 5 years ago

So I got a game where there is an arena and people fight in it. Then I got an Event which triggers that 4 walls spawn and they shrink so all players are forced to move in the middle of the arena. Everything works fine etc BUT If I want to add a deathscript to the walls so they acutally kill you if you touch it, the performance will completly go down. I think its because it is checking everything it touches something to see if it is a hum or not.

Any Idea how to handle this performance wise and only kill the player?

function KillPlayer(part)
    h = part.Parent:findFirstChild("Humanoid")
    if h ~= nil then
        h.Health = 0
    end
end

script.Parent.Touched:connect(KillPlayer)

0
u might wanna try h:TakeDamage(100) TheluaBanana 946 — 5y
0
or use breakjoints theking48989987 2147 — 5y
0
or h:TakeDamage(h.MaxHealth) EliteRayGawnX2 124 — 5y
2
Weird. It shouldn't cause a peformance drop Amiaa16 3227 — 5y
View all comments (7 more)
0
unless there is some other factor at play here theking48989987 2147 — 5y
0
:TakeDamage() doesn't damage the player if they have a force field tho User#23365 30 — 5y
0
just use debounce Metraria 17 — 5y
0
Maybe try adding a wait() ? That always helps me with lag TheGreenSuperman 85 — 5y
0
Breakjoints didnt work, tried it too. Paintertable 171 — 5y
0
Breakjoints didnt work, i tried it too. so weird. Paintertable 171 — 5y
0
You guys need to read my text on top. Im moving the walls btw, so im using TweenService maybe that. Paintertable 171 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

I can imagine this lagging if:

  • You have this script copied in tens or hundreds of parts
  • The wall parts are very large

You say these parts are moving using TweenService. If the walls are also large, I'm not surprised it's lagging! You are likely asking Roblox to essentially scan a huge area and report to you every part that it can find every frame (since TweenService runs constantly).

To fix this, you need a different approach - every frame, use math to check whether a player is "in bounds" or else in contact with the death wall. If they're out of bounds (but still in the map area -- ex, not in a lobby), then set their health to 0.

0
alright! Thats a nice answer. Thats probably it because the Walls are pretty huge due to the arena size. Thanks and I'LL use another code for it :)) Is it better to move it with CFrame then? Paintertable 171 — 5y
0
Switching to CFrame won't solve the problem (and Tweening is a good choice anyway) - you need to have a loop that checks to see if anyone is colliding with a wall every frame (ex a "while true do wait() --[[check players here]] end" loop). chess123mate 5873 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You probably need to use a debounce.

If you don't know what a debounce is here's a basic explanation:

local debounce = true

function touched()
    if debounce == true then
        debounce = false
        print("I have been touched!")
        wait() -- How many seconds until it can be touched again
        debounce = true 
    end
end

script.Parent.Touched:connect(touched)

So if you wanted to apply this to your script then you would write something like this:

local debounce = true

function KillPlayer(part)
    if debounce == true then
        debounce = false
        h = part.Parent:findFirstChild("Humanoid")
        if h ~= nil then
            h.Health = 0
        end
        wait()
        debounce = true
    end
end

script.Parent.Touched:connect(KillPlayer)

I hoped this helped you!

0
This might work. I'll try it later out, Thanks! Paintertable 171 — 5y
0
It didnt.. That is so weird. Im using TweenService to move the walls btw. Paintertable 171 — 5y
0
Maybe give me a example of moving the Object etc plus killing players? Paintertable 171 — 5y
0
Debounce won't help much - the original script doesn't have any yielding commands (so it's not needed for correctness); all it does is skip some of the Touch events. chess123mate 5873 — 5y
0
Ah I see. firestarroblox123 440 — 5y

Answer this question