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

Having a problem with .TouchEnded event {Lag}?

Asked by 7 years ago

Recently been trying to make a playarea script which will damage the player if he's out of that zone(inside the Part). I've done the script, though whenever I'm in the zone it starts lagging like crazy after some time. [Note: the zone/part also shrinks] :


local Damage = 10 local Enabled = true function onTouch(hit) Enabled = false local Character = hit.Parent local Player = game.Players:FindFirstChild(Character.Name) if not Character:findFirstChild("Humanoid") then return end if Player.PlayerGui:findFirstChild("WarnGui") then Player.PlayerGui.WarnGui:Remove() end Enabled = true script.Parent.Area.TouchEnded:connect(function() if Enabled == true then Enabled = false local GUI = script.WarnGui:Clone() GUI.Parent = Player.PlayerGui while true do wait(1) if Enabled == false then Character.Humanoid.Health = Character.Humanoid.Health - Damage else break end end end end) end script.Parent.Area.Touched:connect(onTouch)

2nd Script that makes the part/zone shrink:

    local Rate = script.Parent.Configuration.Rate.Value
    function shrink()
for i = 1, 1000 do
wait(Rate)
script.Parent.Area.Size = script.Parent.Area.Size - Vector3.new(1, 0, 1)
end
    end
    shrink()

Answer this question