#Most efficient way to do this?

1 messages · Page 1 of 1 (latest)

bronze cloak
#

im trying to remake the EFT door system (GUI based, with a GUI appearing on your screen when you get close enough to the door and look near the handle), and I need to know if theres a more efficient way of making this script work.

local UI = game.Players.LocalPlayer.PlayerGui:WaitForChild("InteractionUI")
local Packet = require(game.ReplicatedStorage.Packet)
local IntMod = require(script.Parent.InteractablesMod)

repeat task.wait() until game.Players.LocalPlayer.CharacterAppearanceLoaded

local remotes = {
    DoorServer = Packet("DoorHandling", Packet.StringLong)
}

game["Run Service"].RenderStepped:Connect(function() -- this makes me cringe but i cant think of any other way of doing this
    for i,v in pairs(workspace.Objects.Doors:GetChildren()) do
        local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - v.DoorPart.Position).Magnitude
        if distance < 7 and IntMod.Door(v:GetAttribute("GUID")) == v then
            local part = v.TriggerPart;
            local cam = workspace.CurrentCamera;
            local length = 7;
            local cfg = RaycastParams.new();
            cfg.FilterDescendantsInstances = {game.Players.LocalPlayer.Character};

            local cast = workspace:Raycast(cam.CFrame.Position, cam.CFrame.LookVector * length, cfg);

            if cast and cast.Instance == part then
                UI.Door.Visible = true
                _G.LookingAtDoor = true
                if v:GetAttribute("Status") == "Closed" then
                    UI.Door.Regular.TextLabel.Text = "OPEN"
                    UI.Door.Regular.Visible = true
                elseif v:GetAttribute("Status") == "Open" then
                    UI.Door.Regular.TextLabel.Text = "CLOSE"
                    UI.Door.Regular.Visible = true
                elseif v:GetAttribute("Status") == "Locked" and game.Players.LocalPlayer.Backpack:FindFirstChild(v:GetAttribute("Key")) ~= nil then
                    UI.Door.Regular.TextLabel.Text = "UNLOCK"
                    UI.Door.Regular.Visible = true
                else
                    UI.Door.Locked.Visible = true
                end
            else
                UI.Door.Visible = false
            end
        end
    end
end)

this code also isn't near finished yet, no server code exists yet.

any tips would be appreciated! if theres any better ways to do things like this please explain so i can adopt it in future scripts

#

the referenced module looks like this:

local Interactables = {}

function Interactables.Door(guid)
    for i,v in pairs(workspace.Objects.Doors:GetChildren()) do
        if v:GetAttribute("GUID") == guid then
            return(v)
        end
    end
end

return Interactables
#

nvm

#

co-worker helped me out

river laurel
#

what do u do for work if u dont mind me asking?

hard snow