For me i try to organize how mine looks.
Mine is filled with comments and spaces.
I try to make mine as easy to read as possible
Like as you can see this attack script for my game.
local attackEvent = game:GetService('ReplicatedStorage'):FindFirstChild('AttackEvents'):FindFirstChild('Gorilla')
local function detectPlayerFromChar(char)
if game:GetService('Players'):GetPlayerFromCharacter(char) then
print('Found the player')
return game:GetService('Players'):GetPlayerFromCharacter(char)
end
end
-- create a part
local function makePart(size,color,po, destroy, t, transparency)
local part = Instance.new('Part')
part.Size = size
part.BrickColor = color
part.CanCollide = false
part.CanTouch = false
part.Anchored = true
part.Transparency = transparency
part.Parent = workspace
if typeof(po) == "Vector3" then
part.CFrame = CFrame.new(po)
else
part.CFrame = po
end
if destroy == true then
game:GetService('Debris'):AddItem(part,t)
end
return part
end
repeat
task.wait(1)
until script.Parent:FindFirstChild('EffectsModule')
local effectsModule = require(script.Parent:FindFirstChild('EffectsModule'))
local mod = require(script:FindFirstChild('ModuleScript'))
local visibleValue = 0.5
attackEvent.Event:Connect(function(player,typeOf,anims)
print(player.Name .. 'Attacked!','Used attack '..typeOf)
local char = player.Character
local mod = require(char:FindFirstChild('CooldownMod'))
if mod.Stuff.Attacking == false then
if typeOf == 'ForwardAttack' and mod.Stuff.onCDFW == false then
print('HARD ATTACK!')
-- anim
local anim = anims.forward
mod.Stuff.onCDFW = true
mod.Stuff.Attacking = true
-- detect for a player
local origin = char.PrimaryPart.Position -- the first po
local root = char.PrimaryPart
-- where the ray fires to
local po2 = root.CFrame * CFrame.new(Vector3.new(0,0,mod.AttackDetails.forwardAttack.detectDistance))
local part = makePart(Vector3.new(1,1,1), BrickColor.new('Lime green'), root.Position, true, 5, visibleValue) -- the fire point
local part2 = makePart(Vector3.new(1,1,1), BrickColor.new('Baby blue'), po2, true, 5, visibleValue) -- where it should fire to. Point in the direction
print('Sending a raycast')
-- send the raycast
local params = RaycastParams.new()
-- direction
print(po2)
local direction = part2.Position - origin
-- send the raycast
local raycastResult = workspace:Raycast(origin,direction)
if raycastResult and raycastResult.Instance then
print('Casted')
local target = raycastResult.Instance
print('Hit '.. target.Name)
local showPart = makePart(Vector3.new(1,1,1),BrickColor.new('Really red'),raycastResult.Position, true, 5, visibleValue) -- where it hit
if target.Parent:FindFirstChild('Humanoid') then
print('There is a hum')
-- hit items
local hitChar = target.Parent
local Hithum = hitChar.Humanoid
local Hitroot = hitChar.PrimaryPart
-- move the char in front of the hitChar
local charCframeToGoTo = Hitroot.CFrame * CFrame.new(Vector3.new(0,0,-2))
char.PrimaryPart.CFrame = charCframeToGoTo
-- point the hit char towards the player who attacked
Hitroot.CFrame = CFrame.new(Hitroot.Position,char.PrimaryPart.Position)
char.PrimaryPart.CFrame = CFrame.new(char.PrimaryPart.Position,Hitroot.Position)
-- play the anim
anim:Play()
local rootAttacking = Hitroot
anim:GetMarkerReachedSignal('End attack'):Connect(function()
-- making sure it is the right function
if rootAttacking == Hitroot then
print(rootAttacking)
-- add knockback
effectsModule.KnockBack(Hitroot,char,mod.AttackDetails.forwardAttack.knockback,mod.AttackDetails.forwardAttack.direction)
print('Attack over')
rootAttacking = nil
effectsModule.Ember(Hithum,100,20,00.3)
end
end)
mod.Stuff.Attacking = true
-- attack is over!
else
print('No Hum')
end
else
print('Hit nothing')
end
wait(mod.Stuff.forwardCD)
mod.Stuff.onCDFW = true
-- down attack
elseif typeOf == 'DownAttack' then
local downMod = mod.AttackDetails.downAttack
-- anim
local anim = anims.forward
-- detect for ground
local origin = char.PrimaryPart.Position -- the first po
local root = char.PrimaryPart
-- where the ray fires to
local po2 = root.CFrame * CFrame.new(Vector3.new(0,downMod.detectDistance,0))
local part = makePart(Vector3.new(1,1,1), BrickColor.new('Lime green'), root.Position, true, 5, visibleValue) -- the fire point
local part2 = makePart(Vector3.new(1,1,1), BrickColor.new('Baby blue'), po2, true, 5, visibleValue) -- where it should fire to. Point in the direction
print('Sending a raycast')
-- send the raycast
-- direction
print(po2)
local direction = part2.Position - origin
-- send the raycast
local raycastResult = workspace:Raycast(origin,direction)
if raycastResult and raycastResult.Instance then
local hitItem = raycastResult.Instance
local hitCFrame = hitItem.CFrame
char.PrimaryPart.CFrame = hitCFrame
end
end
end
end)
I mean hey If i can read it then it works!