Semantic Compression of these changed events

So, I’m making a game attempting to compress, and use the least lines while executing the most efficient/effective ways of running without making it look messy (Thats a lot of stuff), but the issue isn’t in the efficiency at the moment, since everything is working in the way I planned it. What I am primarily bothered by, is the fact that I have Changed events in the place where only UIS should be running, and now, it looks kind of messy to me.
I’ll show the userinput scripts, then the stark contrast which is the changed connections at the bottom of the local.



Then, the changeds

It’s too much, and if I could get some slight assistance on compressing it, I would appreciate it very much.

Are you asking on how you would switch from micro-managing events like with GetAttributeChangedSignal to macro-managing like with InputBegan?

If that’s the case, you could simply rewrite your changed events using AttributeChanged:

Player.AttributeChanged:Connect(function(Attribute)
	if Attribute == "Ragdoll" then
		...
		return
	end
	
	if Attribute == "Blocking" then
		...
		return
	end
end)

You could also replace that coroutine.wrap with:

task.spawn(ProcessInput, Input, input, Action, ActionClass)

(Also, try to paste your code when formatting instead of taking a screenshot)

What would be the purpose behind ProcessInput?

It was just a recommendation for your first two code samples. Instead of wrapping a function to run another function with coroutine.wrap, you could just use the ProcessInput function directly with task.spawn.

I recommended using task.spawn instead because it doesn’t hide error messages which the coroutine library is known to do and its overall cleaner to work with.

(Also, if you or someone seeing this in the future is confused, task.spawn takes the function from the first argument and passes the rest as parameters for when it runs. The same is true for task.delay and task.defer.)

1 Like