> Mods and admins, the title is all about the desc... What is the matter???
Question is title.
So i have a problem, this is the part that it runs and doesn't work:
function GetNewAxisX(pl) if pl~=nil then if pl.Character then if pl.Character:findFirstChild('Head')~=nil then if pl.Character:findFirstChild('Head'):IsA('BasePart') then return pl.Character.Head.Rotation.Z / pl.Character.Head.Rotation.X end end end end end
Before you ask... YES, Variable 'Part' is a part, this is a script (Localscript isn't the problem).
The script is supposed to when we mouselock it appears in-front of our head (even when were not mouselocking)
any help?
This is a site for people to help you - they may help with things you didn't think needed to be improved.
Nonetheless, style is very important for keeping your code maintainable, clean, and pretty. You can choose to disregard the suggestions, but keep them in mind because at times they will make code much nicer.
~= nil
is redundant and unnecessary.
It (in my opinion) is more intuitive / simpler to say if pl.Character then
, etc.
Also, we know that Head
is in fact a child of pl.Character
so we don't need to use FindFirstChild
the second time. We can probably assume that if Head
is in a player's Character, it is in fact a part, so that can be probably be removed.
FindFirstChild
ought to be uppercase according to ROBLOX's current stance on naming.
function GetNewAxisX(pl) if pl then if pl.Character then if pl.Character:FindFirstChild('Head') then if pl.Character.Head:IsA('BasePart') then -- Probably not necessary ...
If you want the direction that the player is looking, just use its CFrame's lookVector (no weird stuff with Rotation
)
return pl.Character.Head.CFrame.lookVector -- A unit vector in the direction they are looking
If you want components of it, request its .x
, .y
, and .z
properties (though usually code will be more elegant when phrased entirely in vectors without referring to the components)