plr should be Player. char should be Character. Try to avoid abbreviations unless necessary
Instance names should be capitalized according to roblox style guide, which is not really necessary but helps to make your code more universally understandable. So if you want to then you should capitalize Tool, Handle, Player, Animation
constants like debouncecooldown should be indicated with screaming snake case, so it should be DEBOUNCE_COOLDOWN unless it changes
local hum:Humanoid = char:FindFirstChild("Humanoid") should have a type error if your code is in strict mode. If you are using type annotations then it’s a good idea to use --!strict at the top of your script anyways. Findfirstchild just returns an instance, so it should be local Humanoid = char:FindFirstChild("Humanoid") :: Humanoid or you can use FindFirstChildWhichIsA
in your for loop in the sickleturbo function, the iterator variable i is defined twice. You should use _ which indicates an unused variable if youre not going to use i
If leaderstats fails to load in time then plr.leaderstats.wheat.Value += 1 will fail. You should instead define leaderstats at the start with waitforchild
wait(debouncecooldown) should be replaced with task.wait (more accurate scheduler)
you should use either PascalCase, snake_case, or camelCase instead of writing variables like debouncecooldown because it’s hard to see where the new words are. The style is also inconsistent with function names like Animate and sickleturbo in the same code
In your sickleturbo function you should get rid of useless new lines. There are two of them after the line debounce = false. This function also has mismatched indentation in the for loops. In the if statement in the nested for loop you should use the guard clause pattern to reduce nesting. You should also be more descriptive with the variable name v. So it should be
for _, hit in game.Workspace:GetPartsInPart(handle) do
for _, tag in hit:GetTags() do
if tag ~= "wheat" then continue end
plr.leaderstats.wheat.Value += 1
end
end
I would also use guard clause in the sickleturbo function to reduce unnecessary nesting
local function sickleTurbo()
if debounce then return end
debounce = true
-- other code
task.wait(debounceCooldown)
debounce = false
end
The function name Animate makes it unclear what the function actually does. Generally function names should have verbs in them, so it should be something like playAnimation
local animator:Animator
if hum:FindFirstChild("Animator") then
animator = hum:FindFirstChild("Animator")
else
animator = Instance.new("Animator", hum)
end
This pattern can be much cleaner with the if then else statement, which would look like
local Animator : Animator = if hum:FindFirstChild("Animator")
then hum:FindFirstChild("Animator")
else Instance.new("Animator", hum)
But i think it might be unnecessary in in the first place because humanoid should always have the animator
On the other hand, like how @ivan866_z said, it’s probably bad architecture to put a server script inside every tool. It’s slow, uses a lot of memory, and hard to scale (hard to add more tools). Instead you should probably just make one system that handles all tools, but it depends on your game.
Overall you need more practice to get the formatting down. Making readable code is absolutely necessary not just for working in teams but also for making development easier for yourself in the future. It’s extremely difficult, tedious, and slow to work on large unreadable code. But don’t obsess too much over readability either