How to stop writing spaghetti code

My brain got though the variables and went “im not reading that then scrolled to the bottom.”

2 Likes

oh yeah the huge number thing was just me playing around lol its not actually meant to be so huge I forgot to change it back

1 Like

if you want more code readability i suggest you make space for your code like this:

local Character = Player.Character
	local Humanoid = Character:FindFirstChild("Humanoid")
	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if Humanoid.Health == 0 then return end

	local ownedFolder = Player:FindFirstChild("ownedFolder")
	local moveObject = ownedFolder:FindFirstChild("PowerPunch")

	if not Player or not Player.Character then return end
	if playerCooldowns[Player] then return end
	if MoveName ~= "PowerPunch" then return end

	if moveObject.Value == false then print("move not owned") return end
	playerCooldowns[Player] = true

it looks SO much better rather than having them all compact.

4 Likes

thank you I’ll keep that in mind next time

2 Likes

instead of couroutine.wrap(functionthing)()

you can do task.spawn(functionthing)

doesn’t need extra brackets at the end

1 Like

I’m a little confused here, your remote Reference is AbilityRemote1, I’m guessing each ability / skill has it’s own remote? But at the same time you receive MoveName in OnServerEvent.

I suggest making AbilityModule that handles all abilities / skills usage with one remote, vfx and main script also seperated.

Also don’t use .Touched for hitbox since it’s really exploitable, I suggest using GetPartBoundsInBox

1 Like

I used to have this problem but i fixed it by making systems that use folders to determine items and one single module script that uses these folders to set up the abilities rather than putting them in one script (example of an enemy system i made)
image

2 Likes

Oh, originally I was going to do each ability have its own remote, but I sorta scrapped that since having like 200 remotes didn’t really appeal to me, so I’m only using one remote for every move.

I don’t think I can use GetPartBoundsInBox for the module I’m using, but I’ll consider it next time when scripting!

1 Like
	["Example"] = {
		["displayName"] = "Example",
		["description"] = "Example",
		["init"] = function()
			--code here
		end
	}

or you can have a table like this for abilities

3 Likes

I don’t think I can use GetPartBoundsInBox for the module I’m using, but I’ll consider it next time when scripting!

what’s the issue?

1 Like

The script itself works fine, I was just wondering if there were better ways to code it because I feel like what I’ve written is messy and redundant code

2 Likes

Ah I see Thank you so much for sharing, I’ll try to implement a system like this next time it seems much more organised than what I have right now

1 Like

read this reply of mine on someones else post

4 Likes

thank you so much this is probably what I’m looking for

Also in there I forgot to mention to FireAllClients so they play the VFX on their end

1 Like

A good tip for game dev is just to code everything like you are giving it to someone else to use (i started doing this and my scripts became much cleaner)

1 Like

I actually got the opposite advice when I was first starting out which was just to write the code and not worry about it being messy. I rarely work with other people or even post about anything at all so I’ve just followed that ever since. Anyways thanks for sharing again!

Its fine to have messy code, take undertale for example (the code is all over the place), but if you want to make your life easier for yourself in future then write clean code for big systems but little things are ok to be messy

1 Like

alright I got it thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.