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

.Touched, lag or incorrect firing?

Asked by
Jackd44 35
10 years ago

Hello, I have recently been in development of my new place. And I have a very simple kill brick that has this code;

function Kill(Plr)
    game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value = false
    Plr.Parent:BreakJoints()
end

script.Parent.Touched:connect(Kill)

The Alive value and such are irrelevant, they do not seem to be creating the fuss. However, sometimes when jumping on a fairly short brick located on top of this kill brick, it will just kill the player anyway. However I've also had scenarios where you can be a few studs above the kill brick, where a death should be impossible to achieve via the kill brick, yet you can still die. This has given me a thought the the script may not be faulty, just the game is lagging. However, I'm clueless on the matter, does anyone have any words of wisdom for this issue?

I wasn't sure if the tag was correct, but it seemed partially relevant, so I used it.

2 answers

Log in to vote
1
Answered by 10 years ago

You need to add a debounce, which can be done two ways, a debounce or checking the value in Alive. I am on my phone, so I will post a better version once I get to a computer.

 function Kill(Plr)
    if game.Players:GetPlayerFromCharacter (Plr.Parent).Alive.Value==true then
        game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value =false
         Plr.Parent:BreakJoints()
    end
end

script.Parent.Touched:connect(Kill)

Or...

function Kill(Plr)
    local Debounce = false
        if Debounce == false then
        Debounce = true
        game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value =false
        Plr.Parent:BreakJoints()
        wait ()
        Debounce = false
    end
end

script.Parent.Touched:connect(Kill)

Way 1 is recommended so no one can survive when both people touch it.

0
Thank you, I completely forgot I needed a debounce. :P The script now pretty much works as it should, and I now think the only cause of the odd deaths I'm having is due to me touching the block, but just not seeing it. Or jumping on rotated blocks that have been CFrame'd into the kill brick cause minor issues. Either way, it works better now, thanks. :) Jackd44 35 — 10y
0
No problem. Comment if you need more help on this issue. FromLegoUniverse 264 — 10y
Ad
Log in to vote
-2
Answered by
modFrost 130
10 years ago
local A = false
script.Parent.Touched:connect(function(Object)
    local Player = game:service'Players':GetPlayerFromCharacter(Object.Parent)
    if Player and not A then
        Player:LoadCharacter()
        A = true
    end
end)
0
That answer will still lag since it will can load the character many times in one hit (may touch the part with both legs and more body parts), and does not have the like game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value =false FromLegoUniverse 264 — 10y
0
Problem solved... modFrost 130 — 10y

Answer this question