This script is for my FPS game. I want to shorten the number of lines. Thanks.
Here is a file download:
https://drive.google.com/uc?export=download&id=1HnwVfk3phDdVqQABXt7wD-10frQ19ZuJ
This script is for my FPS game. I want to shorten the number of lines. Thanks.
Here is a file download:
https://drive.google.com/uc?export=download&id=1HnwVfk3phDdVqQABXt7wD-10frQ19ZuJ
Is there a particular script you wanted us to look at?
There’s quite a few here

DrWhoInTARDIS
Is there a particular script you wanted us to look at?
There’s quite a few here
[img]
Late reply. Sorry.
There should be a framework script. Thats what I want reviewed.
First thing that I notice is using “WaitForChild” to get humanoid, I would recommend storing the character’s humanoid in a variable, but still check that it’s valid. Same with GetMouse().
gertkeno
First thing that I notice is using “WaitForChild” to get humanoid, I would recommend storing the character’s humanoid in a variable, but still check that it’s valid. Same with GetMouse().
What way ya mean
local rootpart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
game:GetService("RunService").RenderStepped:Connect(function()
if vm then
if rootpart.Velocity.Magnitude >= 0.01 then
moving = true
else
moving = false
end
-- also the above if/then/else could be used directly like this
moving = rootpart.Velocity.Magnitude >= 0.01
if moving then
-- continued...
In this example roblox stores the rootpart outside of RenderStepped:Connect, this means it doesn’t have to look it up every single frame. Avoid yielding calls in often run code like RenderStepped which is run every frame, yielding functions include WaitForChild, and roblox usually marks these function with the suffix “Async” but it’s always good to make sure online.
WaitForChild doesn’t always yield but it still incurs a performance hit since it uses FindFirstChild which you should also store results for. Yielding calls use roblox’s task scheduler, which takes a lot of time and can produce unexpected results.
if the player dies, the variable will be useless
You’re correct and the solution would be to put the framework script in StarterCharacterScripts.
Alternatively if the script is not meant for being cloned into a character (like a script in server script service), you would instead have a function that’s in charge of setting the variable upon the character being added. This should be hooked up to the player.CharacterAdded event, wait for the root part to show up via :WaitForChild(), and then assign that root part to the variable. This way you’ll always have the variable assigned to the proper part.
Literally everyone:
stuff
I have added the changes in the script. Any more advice