#code efficiency / readability

6 messages · Page 1 of 1 (latest)

vernal spindle
#
local ContextActionService = game.ContextActionService
local ReplicatedStorage = game.ReplicatedStorage
local PlayerService = game.Players.LocalPlayer
local TweenService = game.TweenService
local RunService = game['Run Service']

local Debounce, Cooldown = os.clock(), 2
local CurrentlyCharging = false
local EventConnection = nil
local CurrentForm = 'Base'
local FormToggled = false
local Execute = nil

local Assets = require(script["Assets Module"])
local Animations = Assets.Animations

local function Transform(Form, State)
    if (State.Name ~= 'Begin') and not (CurrentlyCharging) then return end
    if (FormToggled) and (CurrentForm ~= Form) then return end
    
    FormToggled = not FormToggled
    CurrentForm = FormToggled and Form or 'Base'
end

local function Begin()
    Animations.Started:Play(.1)
    
    local function Finished()
        Animations.Completed:Play(.1)
    end
    
    EventConnection = Assets.Animations.Started.Stopped:Connect(Finished)
end

local function End(State)    
    if (State == 'Begin') then return end EventConnection:Disconnect()
    
    if (Animations.Completed.IsPlaying) then
        Animations.Completed:Stop(.15)
    end 
end

local function Charge(_, State)
    CurrentlyCharging = not CurrentlyCharging
    
    Execute = CurrentlyCharging and Begin() or End(State.Name)
end

for Key, Value in (Assets.Forms) do
    ContextActionService:BindAction(Key, Transform, false, Enum.KeyCode[Value])
end

ContextActionService:BindAction('Charging', Charge, false, Enum.KeyCode.C)```
i've been scripting on roblox for two days and i've watched a few of alvin blox's tutorials so i decided to put the knowledge to test

i've got this wip goku charging system that i'd like to know if i can do better in terms of readability and much more efficient methods
i'm still extremely knew so i'd love shorter explanations, thanks
proper atlas
#

hardly think AlvinBlox would teach people to code like this, also in two days most probably not

#

eighter u used an Ai, or used someone elses code

#

ah yes

#

but sure tips still can come

#

indentation in this code is very inconsistent