local function getCharacterHeight(char)
local headHeight = char.Head.Size.Y
local upperTorsoHeight = char.UpperTorso.Size.Y
local lowerTorsoHeight = char.LowerTorso.Size.Y
local upperLegHeight = char.LeftUpperLeg.Size.Y / 2 + char.RightUpperLeg.Size.Y / 2 --in case both legs are different sizes
local lowerLegHeight = char.LeftLowerLeg.Size.Y / 2 + char.RightLowerLeg.Size.Y / 2
local feet = char.LeftFoot.Size.Y / 2 + char.RightFoot.Size.Y / 2
return headHeight + upperTorsoHeight + lowerTorsoHeight + upperLegHeight + lowerLegHeight + feet
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local characterHeight = getCharacterHeight(character)
print(characterHeight)
--rest of code
See if this helps you any, you can access the ‘size’ part of the return value
or
Been trying for a while. Can’t seem to get it off the middle of the character.
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local estimatedHeight = tonumber(character:GetBoundingBox().Y)
print(estimatedHeight)
local newAttachment = Instance.new("Attachment")
newAttachment.Name = "NewAttachment"
newAttachment.Parent = character.HumanoidRootPart
local newPart = Instance.new("Part")
newPart.Name = "NewPart"
newPart.Size = Vector3.new(4, 0.1, 4)--splash part goes at base of character
newPart.CanCollide = false
newPart.Position = character.PrimaryPart.Position - Vector3.new(0, estimatedHeight / 2, 0)
newPart.Parent = character.UpperTorso
--print(newPart.Position)
local newWeld = Instance.new("Weld")
newWeld.Name = "NewWeld"
newWeld.Part0 = character.UpperTorso
newWeld.Part1 = newPart
newWeld.Parent = character.UpperTorso
--rest of code
I’m not sure, but here you are testing the height on an event that fires when a player connects, but you actually show a rig which, atleast as far as I know, is not a player (I might be wrong here). Have you checked if maybe your player can actually fit next to that part? Could be that your character is now higher than the Rig as you may use different versions etc.
Keep in mind welds reset any to-object-space differentiation. Try WeldConstraint in this example.
Also, you could try one of the methods Roblox uses to get hip height but for character height (maybe not their exact internal method but close enough). (Since this calculates for animation idles as well)
local char
local head = char.Head
local foot = char.LeftFoot
local height = (head.Position.Y - foot.Position.Y) + (head.Size.Y - foot.Size.Y) * 0.5
You can use Character:GetBoundingBox()
Oh, I did not know that. I will look into that in the morning.
Yeah I used my rig as the height example, the second image is my character where I use the bounding box to get the height of the character (I’ll probably add in a percentage change to get it closer to my characters height) and since it’s a percentage when the player is taller or shorter it should match the values as closely as I can get them. Once I have the height I can divide by two as a variable to set the parts negative height from the cframe of the model. That should imo set the part at the characters feet (I hope).
If I’m going about this all wrong I would love to hear alternatives. Ty all so far for your replies.
What is it you are trying to accomplish? I see you have a splash part. Maybe there is a better way to do this that fits your needs.
Character height should just be 6 * HeightScale
, the latter of which you can get from the HumanoidDescription or from BodyHeightScale in the Humanoid object.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
local newPart = Instance.new("Part")
newPart.Name = "NewPart"
newPart.Size = Vector3.new(4, 0.1, 4)--splash part goes at base of character
newPart.CanCollide = false
newPart:PivotTo(hrp.CFrame) --because the weld will snap into place when setting its C0 and C1, we only need to get it close to the character
newPart.Parent = character.UpperTorso --not sure why you need this to be parented into upper torso, but I would parent it to humanodidrootpart
local offset = humanoid.HipHeight + (hrp.Size.Y/2)
offset = offset - (newPart.Size.Y/2) --this makes where bottom point of newPart is sittion on ground, not mid point of newPart
print(offset)
local newWeld = Instance.new("Weld")
newWeld.Name = "NewWeld"
newWeld.Part0 = hrp --needs to be humanoid root part as this is where our offset is starting from
newWeld.Part1 = newPart
newWeld.C0 = CFrame.new()
newWeld.C1 = CFrame.new(0,offset,0)
newWeld.Parent = character.UpperTorso --not sure why you need this to be parented into upper torso, but I would parent it to humanodidrootpart
--rest of code
end)
end)
Yeah I had that all day on HRP, I was playing around with settings, torso, feet (feet btw is ridiculous as you can only choose one side).
lol, yeah feet.
It really doesn’t matter where you parent the items, other than for your own organization.
The only thing that really matters is the weld.Part0 and weld.Part1, because this sets the start point for their C0 and C1 cframes.
Let me know if the code I provided works for you.
Use Motor6D if you want it to always fit to the root
Thank you all for the help. Final script reads (formatting aside)
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
--Making sure they're 100% loaded b4 adding things
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local newAttachment = Instance.new("Attachment")
newAttachment.Name = "NewAttachment"
newAttachment.Parent = character.HumanoidRootPart
local particlesFolder = ServerStorage.Particles
local rainPart = particlesFolder.RainPart:Clone()
local offset = humanoid.HipHeight + (humanoidRootPart.Size.Y/2)
offset = offset - (rainPart.PrimaryPart.Size.Y/2)
rainPart.Name = "RainPart"
rainPart.PrimaryPart.Transparency = 0
rainPart.RainingPart.Transparency = 0
rainPart.PrimaryPart.CanCollide = false
rainPart.RainingPart.CanCollide = false
rainPart:PivotTo(character.HumanoidRootPart.CFrame - Vector3.new(0,offset,0))
rainPart.Parent = character.HumanoidRootPart
local newWeld = Instance.new("WeldConstraint")
newWeld.Name = "NewWeldConstraint"
newWeld.Part0 = humanoidRootPart
newWeld.Part1 = rainPart.PrimaryPart
newWeld.Parent = character.HumanoidRootPart
--rest of code
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.