#How do I organize/optimize this better?
1 messages · Page 1 of 1 (latest)
yes
you can
very much
you can just set the attribute for the endtime of stun
Isn’t that worse?
and to check if theyre in the state just compare current time to endtime
then u can boom the heartbeat check
Wdym by boom
delete
u dont need the heartbeat connect
and for handling stun you can do it on client
as in
the walkspeed
that way u can nuke a relatively expensive heartbeat server connection
Isn’t that insecure?
they can change their walkspeed anyway
doesnt matter what the server says
@torn plaza
Isn’t this less optimized btw
wdym
attributes use a hashmap so lookups are O(1)
Using attributes is less optimized than using arrays cuz they have to pass through the lua - c++ layer, no?
but they replicate to client which lets u ditch that (on server) runservice connection
I see
So I should use a renderstepped or something on client instead?
also you should just be able to assume state is "idle" if the endtime of last state is less than current time
integrate it with your sprint script (if you have one)
I don’t 😢
So do I check for the attribute every frame?
that is a way you could do it for client

Wdym 
@torn plazaalso I tested it just now
attributes are a bit slower than indexing an array
but
it doesnt matter
this is for 50000000 lookups
arrays (top)
attributes(bottom)
Heartbeats themselves aren’t really expensive though, it’s what you do inside, no?
Since I’m mainly iterating through an array I don’t think it’s that expensive
The more optimized the better am I right
Still think it's better to handle that on client
Since the stun will end the exact time intead of having to replicate the walk speed change
@jade kindle can I get ur opinion
@jade kindle i need this gng
** You are now Level 14! **
@vocal walrus u got me tho right
wat
why me 
Sry I’m busy
Cuz ur s3 and I need help
well first, i'd have appreciated if you put the code in the thread so people can refer to it more easily
second; your code is pretty bad
you're optimizing bad code
.... get your code right first, before you make it fast.
How is it bad
well for starters you don't clean up entries in M1IndexMap or M1Characters so they will build up forever without limit, this is a memory leak.
Yeah ima add that but what else
second this does not scale ```lua
local M1Character = {}
local M1Debounce = {}
local M1Number = {}
local M1IndexMap = {}
Wdym by that
its not flexible enough to build on it
Why isn’t it flexible?
3rd ```lua
RunService.Heartbeat:Connect(function()
for i = #StunnedCharacters, 1, -1 do
4th ```lua
function module.HitVFX(char)
local att = vfxpart.HitVFX:Clone()
att.Parent = char.Torso
att.Hit:Emit(10)
game.Debris:AddItem(att, 0.4)
local SFX = game:GetService("SoundService").punchSFX:Clone()
SFX.Parent = char
--SFX:Play()
game.Debris:AddItem(SFX, 1)
end``` static hitfx
Why isn’t it flexible tho
5th, this nonsense repeated lua if WhatToFetch == "Debounce" then return M1Debounce[index] elseif WhatToFetch == "Number" then return M1Number[index] end
6th, this is overengineered for no good reason lua local char = StunnedCharacters[i] if i < #StunnedCharacters then local lastIndex = #StunnedCharacters local lastChar = StunnedCharacters[lastIndex] StunnedCharacters[i] = lastChar StunEndTime[i] = StunEndTime[lastIndex] stunIndexMap[lastChar] = i
Wdym by over engineered
there's not really a good reason to have so many tables for this
just use one
combatData[char]={cooldowns={} etc
Isn’t it more optimized
Cuz organized arrays are read easier than dictionaries due to dictionaries having scattered data
your obsession with optimization here is misguided
it's a common problem, see it all the time
believe it or not, you cannot optimize past 60fps you dingus
Btw you still haven’t answered my question
i already did. this does not scale
What do you mean by that
adding to it is more difficult than it needs to be
local vfxpart = workspace:WaitForChild("VFXPart") lol
that's reason #7
reason #8 hardcoded speeds ```lua
local function resetHumanoidSetting(char)
local humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
local function stunHumanoid(char)
local humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
end
can you tell me why you think it is more optimized?
specifically where are you getting this information from
Extensive research
Give me some specifications gng 
the only positive thing i can really say about it is that it doesn't appear to be broken, aside from the memory leak
This saddens me
the only benefit of doing all this table work is so you can do this if statement ```lua
RunService.Heartbeat:Connect(function()
for i = #StunnedCharacters, 1, -1 do
if time() >= StunEndTime[i] then```
... a check you didn't even need in the first place and shouldn't be doing as already explained
task.delay(stunDuration, reviveHumanoid, hum) derp
It’s more optimized and customizable tho
you do need it stacking though so you task.cancel(reviveHumanoidQueue[hum]) task.spawn(...) but that's still less work than doing all this stuff
i mean, you asked for advice and i'm telling you this is wasted effort but i mean if you want to continue down the road of optimizing things that don't need it, well hey it's your project not mine
Why not optimize if I can though I don’t understand what’s wrong with adding extra optimization if I can
i can tell you haven't worked on large projects before
Btw what’s wrong with this cuz it shouldn’t cause any issues, no?
I don’t have streaming enabled
Oh I should store it in replicated storage right
hahahahahaha yeah and what's funny is you throw it away at the first opportunity in 90% of the places you use it ```lua
function module.CheckBlock(char)
local index = blockIndexMap[char]
...
function module.EndBlock(char)
local index = blockIndexMap[char]
...
function module.StartBlock(char)
local index = blockIndexMap[char]
...
function module.CheckStun(char)
local index = stunIndexMap[char]
...
function module.Stun(char, StunTime)
local index = stunIndexMap[char]
...
function module.FetchM1Data(char, WhatToFetch)
local index = M1IndexMap[char]
...
function module.ChangeM1Info(char, change, changevalue)
local index = M1IndexMap[char]
...
function module.AddM1Character(char)
local index = M1IndexMap[char]
this is what premature optimization gets you
stop optimizing stuff that doesnt need it
but hey what do i know
and i was talking about this
OpTiMiZaTiOn!
Bro did not answer the question 
let's do dumb things to optimize memory lookup but immediately thrown out all the work done with higher memory overhead, and then disable the one feature that makes roblox reliable on mobile. Why? Because some guy on reddit said it was mOrE oPtImIzEd
Isn’t this better cuz there’s less data being stored in the dictionary
You still haven’t told me if I should use replicated storage or not

you would need an exceptionally small game to justify turning off streaming
Yn js answer the question bro 😭 ✌️
in a nutshell the fact you're relying on the opinions of others whether or not something is more optimal should on its own be a tell that you don't know enough to even be wasting your time with this
just use a regular dict like a normal person
frankly you should be more concerned about the endpoints than microoptimizations like this. if, and only if, it becomes a bottleneck should come back to it and consider maybe reducing cpu usage
coz again, you cannot optimize past 60fps
the biggest problem with all this is the time it takes to develop this stuff with these added "optimizations" when your time could've been better spent making it more robust and do more things, or working on other aspects of your game
Sure but I can optimize to 60 fps
It’s not a full game it’s just a combat system for practice so I’m tryna optimize it as much as possible before i possibly sell it
from experience most people who want this are making their own for the same reason you are. as far as selling it goes, no one is going to buy it unless it has a good reputation. here's 3 i found for free after 30 seconds of googling:
https://devforum.roblox.com/t/open-source-simple-combat-system-with-blocking-and-stun/2484521
https://devforum.roblox.com/t/simple-m1-combat-system/2560101
https://devforum.roblox.com/t/another-open-sourced-combat-system/2828863
that's before the thousands of tutorials on it, because every ipad kid wants their own tsb clone:
https://www.youtube.com/watch?v=AX3rWUj5gRo
https://www.youtube.com/watch?v=BkvVhIlPeL8
https://www.youtube.com/watch?v=lX4CF9CQTUA
https://www.youtube.com/watch?v=zZmuuRhdUgQ
the biggest take-away i hope you take from all this is precisely this. Optimize your time first. You could spend a week microoptimizing an unfinished part of your project only to come back later and re-do it all because your first technique wasn't good enough for the job. that is dev time and effort you could have better spent doing literally anything else. it may feel like you have infinite time but you don't.
Can you PLEASE tell me if I should use replicated storage or not 😭 ✌️
do your own due dilligence, do your research, and you tell me
Holy gatekeep bro 💔
you'll extensively research people's opinions of a subject, but you won't research the subject itself?
Makes sense to me! 💃
Cuz it’s a yes or no question 
in case you haven't noticed, the priority with optimization is not actually optimal code performance; the priority is actually optimizing development time and effort, and understanding for yourself how and why one technique is better than another coz if you don't know which technique is better without someone telling you which one with a 'trust me bro' you don't know anything about optimizing.
I did extensive research
Also can you answer my question
i do understand that newbie and beginner devs place a lot of highlight and emphasis on performant code, but it's really overdone to an unnecessarily obsessive degree. this is the 20th centure, we're not in the 90's anymore where the best hardware you could expect was 3.5MHz, 128KB ram Super Nintendo. modern computers have multi-core cpu's in the range of GHz, and similar in the GB's of ram. It's okay to have some flawed code, the only goal is staying above 60fps.
You’re egdinnnng me bro 😭
I ain’t no beginner
you don't know whether or not to put a template in replicatedstorage or in workspace, and you disabled streaming mode. you're a beginner.
I don’t dillydally Iike that
Anything but answer my question
💔 🙏 🥀 🎋 😢 
you're not asking for a fact you're asking for an opinion
this is a fact
I see some games with their vfx like under a map or something so that’s why I thought that it could be a reasonable course of action but I guess not
"should" questions are an opinion
This isn’t ELA class bro 😭 😭 ✌️
I guess I’ll take the path of optimization 😔 ✌️
i have answered your first question tho
how can you improve, organize, and optimize this better? as explained above, your first step is understanding for yourself how to tell if something is better improved, organized, or optimized. relying on random people's opinions as to what is best for what you're working on is probably the worst way to improve, organize, and optimize your code.
when you do that properly, your second question is already answered in the same process 
Bro you are not Shakespeare
My boy seek got me tho 😂 ✌️ 😅
and deepseek has never been wrong about anything, ever.
it has never been uncertain of anything either
I make sure to do research on stuff I think it’s lying about
and there's no flaws or faults with relying on deepseek's advice whatsoever.
and as long as it feels right, it must be right 
I don’t rely on it
I use it as a building block
Cuz scripters be gatekeeping advice fr
i have not gatekept advice from you
not that i had any obligation to share that advice with you in the first place, but i chose to do so anyway
for your benefit
You literally haven’t even told me where to store my vfx part 😭 💔
give a man a fish, feed him for a day. teach a man to fish, feed him for a lifetime.
if i spoonfeed you my opinion on what i think you should do with your project is not going to help you at all tomorrow.
Text book definition gatekeeping yo 😭 😭 😭 😭 😭
and besides, why are you letting people tell you what to do wtf
I’m asking for advice and criticism that could help me long term
in my opinion what you should do with your combat system is transfer a million robux to me 
you see? 
i have done this at length in this thread
or are you telling me this is not advice and criticism that could help you long term?
Sure but for the icing on the cake could you tell me where to store my vfx part
store it in Lighting service
bro used his own mind to make a decision. i'm proud 🥳 good job!
This entire script is my decision watch your tone young man
is it really though
you're using dod pattern because some guy on reddit said it was optimized, was that your decision too, or are you just obediently doing as you're told?
I did extensive research on why dod is better than oop/ the benefits of each and applied that to my code
That Reddit post was just a piece of the puzzle
i suppose deciding to blindly follow other people's instructions and opinions is itself a decision
It’s not but doing your research and finding what works for you is
I’m tryna practice different paradigms anyways
or, if not totally blind, it would be blindly following OpTiMiZaTiOn without regard for the impact on development processes. spending days, weeks optimizing something that never needed it in the first place instead of making things functional, robust, and stable. not a decision I would make, but you're free to make those decisions yourself
'Murica! 🦅
that's funny
after the conversation that has just occurred
Might as well practice optimization techniques on a smaller project tho
Just for reference yknow
if i might suggest, in your practices, benchmark everything
I’m very serious 😠
optimizations are merely a suggestion if you do not have benchmark stats to prove it
Yeah I should add more print statements
you should typically play vfx on client
ngl
I didnt wanna say nun bout the issues with it
they only asked for optimizing
anything short of benchmarks is mere speculation and not worth anyone's time. in its place i suggest best practices instead of chasing the dragon of perfect performance; it is a fool's errand in the real world, there is no 0cpu method. But what do i know, i mean you can keep chasing the dragon and never release anything along the way if you really want to, idk i'm not your dad and you can make your own decisions 🤷
it's like, why doesn't everyone just simply switch to a dvorak keyboard? it's more efficient!
have fun researching why that sounds good on paper but doesn't work in the real world.
in my experience the scripts dont really matter unless its sum ridiculous like spawning 100+projectiles
or
sum thaty requires a lot of iterations
^ for roblox that is
@torn plazaalso btw if u really care that much, using : is faster than using .
local q = {}
q.Name = "hi"
function q.GetName()
local a = q.Name
end
function q:GetName2()
local a = self.Name
end
local s = tick()
for i=1, 5e7 do
q.GetName()
end
print(tick() - s)
s = tick()
for i=1,5e7 do
q:GetName2()
end
print(tick() - s)
^ try it yourself
It is
That requires using a dictionary though
Mb to ask cause I was really curious about what u said here. So ur saying that you shouldn’t be spending so much time optimizing something so much but rather finishing that system instead?
I prob read it wrong but that’s my still
yes
people have a hard time accepting that but it is true particularly for beginners
it's okay to make bad code
yea Alr 😭
So should u like
Optimize everything once you’re done with it?
cause when I’m scripting I’m always thinking of scenarios that could be more optimized or readable but I feel like I shouldn’t do it and save it for later
yea just take note of the dumb stuff that you end up doing and improve that for next iteration
Alr alr
iteration is key - you will never make it right the first time
I’ll take note of this
This whole discussion was actually worth reading icl 😭
but you can optimize to 60 fps
holy bar
i js did the same thing cause i was looking for other ppl who are doing senko's combat tutorial to see if its good for beginners
i js finished brawl dev's beginner series