I have here a script that sets the height of a Attachment to the floor depending on the character’s height. The code works, but I couldn’t get it to the Floor itself, its stuck midway my legs.
PLAYERS.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
if plr:GetRankInGroup(GROUP_ID) == 6 or MPS:UserOwnsGamePassAsync(plr.UserId, VIP_ID) then
local HRP = chr:WaitForChild("HumanoidRootPart")
local HUM = chr:WaitForChild("Humanoid")
local FOOT = chr:WaitForChild("RightFoot") or chr:WaitForChild("Right Leg")
local CLONE = VIP_BOOSTER:Clone()
for i, v in pairs(CLONE:GetChildren()) do
v.Parent = HRP
if v.Name == "Aura_Bottom" then
local offset = HUM.HipHeight + (HRP.Size.Y/2)
offset = offset - (v.Position.Y/2)
print(offset)
end
end
end
end)
end)
The overall height of the humanoid can be described in the following formula:
Height = (0.5 * RootPart.Size.Y) + HipHeight
*It seems like that’s already being done in the offset variable in the code you posted, though, so maybe the calculation that was made afterwards is causing the discrepancy?
The code is working, however I can’t seem to detect the Attachment’s Y position and whenever I check the Model, its set to the standard size. But whenever it prints, the code actually works.
Ah, I see. After looking back at the code, it seems like the issue might just be that the offset was never applied to the Attachment.
The code only defines the offset given the height of the Character (and updates it once more afterwards) but from that point onward, the variable is never used to update any properties of the Attachment afterwards, which is why it’s printing the correct value but nothing is changing on the Character model itself:
This is the Code I believe is not working properly, and I think I need to use CFrame, can you help me out with this one, I’m not really fond of Math when it comes to LUA
The offset looks like it was calculated correctly, so that part probably isn’t the issue. You need to use the value afterwards to update the position of the Attachment (e.g. v.Position = offset, *or in this case, it would likely be v.Position = Vector3.new(v.Position.X, offset, v.Position.Z), but my brain is a bit fried right now so maybe I am incorrect haha), since right now, the script is figuring out the necessary offset to make it appear in the correct spot but it’s not changing where the Attachment is positioned.
well its not just the overall height I’m trying to get from the Character itself, I’m trying to get the position of the HumanoidRootPart to the Floor itself so I can place the Attachment at the Bottom Floor.
local Height = character:GetExtentsSize().Y
local HumanoidRootPartCFrame = character.HumanoidRootPart.CFrame
local BottomPosition = (HumanoidRootPartCFrame * CFrame.new(0,Height/2,0)).Position
No not really, I just tested it out with various rigs and it works flawlessly and does get the accurate position of the player’s floor.
Alternatively, one can also use rayCasts!
local params = RaycastParams.new()
params.FilterDescendantInstances = {character}
local ray = workspace:RayCast(HumanoidRootPart.Position,Vector3.yAxis*-Height/2,params)
print(ray.Position)
your solution can be used as an easy alternatives, but right now the code I got help with @StrongBigeMan9 worked flawlessly and I tried it with various character sizes that I have (plushie ava, tall ava, normal ava, etc)
Okay then mark theirs as the solution? I am just here to provide an easier alternative to the post. If their post helped you then it’s good, mark theirs as solution.