I have looked at many other topic on the devforum and non of them worked. Ive spent the last 3-4 hours trying many different solutions. And ive gotten as far as this `local autocorrect = true
local autocorrect = true
function recalculateHipHeight(character)
script.Parent.Parent:FindFirstChild("Humanoid").HipHeight = (0.5 * script.Parent.Parent:FindFirstChild("HumanoidRootPart").Size.Y) + script.Parent.Parent:FindFirstChild("Humanoid").HipHeight
end
function recalculateHipHeight2(character)
script.Parent.Parent:FindFirstChild("Humanoid").HipHeight = script.Parent.Parent:FindFirstChild("LeftLeg").HipHeight.Size.Y + (0.5 * script.Parent.Parent:FindFirstChild("HumanoidRootPart").HipHeight.Size.Y) + script.Parent.Parent:FindFirstChild("Humanoid").HipHeight
end
function PlayerRandomizer()
pcall(function()
script.Parent.Parent:FindFirstChild("HumanoidRootPart").Anchored = true
end)
local ids = require(game.Workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Owner.Value).FriendUserID)
if #ids == 0 then
script.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent.AISpawn.CFrame)
return
else
local succses, errormess = pcall(function()
local ChoosenID = ids[math.random(1,#ids)]
local Name = game.Players:GetNameFromUserIdAsync(ChoosenID)
local Description = game.Players:GetHumanoidDescriptionFromUserId(ChoosenID)
script.Parent.Parent.Humanoid:ApplyDescription(Description)
script.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent.AISpawn.CFrame)
pcall(function()
script.Parent.Parent:FindFirstChild("HumanoidRootPart").Anchored = true
end)
end)
if not succses then
PlayerRandomizer()
end
local s, e = pcall(function()
spawn(function()
while wait() do
script.Parent.Parent:FindFirstChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
script.Parent.Parent:FindFirstChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
script.Parent.Parent:FindFirstChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
end
end)
spawn(function()
while wait() do
if autocorrect == true then
script.Parent.Parent:FindFirstChild("HumanoidRootPart").Velocity = Vector3.new(0,1,0)
end
end
end)
end)
if not s then
print(e)
end
for i,v in pairs(script.Parent.Parent:GetChildren()) do
if v:IsA("BasePart") then
v.CollisionGroupId = 1
end
end
wait(1)
local ss, ee = pcall(function()
if script.Parent.Parent:FindFirstChild("LeftFoot") then
recalculateHipHeight(script.Parent.Parent)
else
recalculateHipHeight2(script.Parent.Parent)
end
end)
if not ss then
print(ee)
end
pcall(function()
script.Parent.Parent:FindFirstChild("HumanoidRootPart").Anchored = false
wait(1)
autocorrect = false
end)
end
end
PlayerRandomizer()
wait(20)
pcall(function()
if script.Parent.Parent ~= nil then
script.Parent.Parent:Destroy()
end
end)
Do you know any way i could prevent that from happening?
Why are you setting the hipheight? That’s not what this post is about if that’s what you’re referring to - it’s for finding the height from the HumanoidRootPart.Position to the ground.
When you’re setting the CFrame of the character, that’s when you’re supposed to be using the methods from the post linked above. You’d do something along the lines of Character:SetPrimaryPartCFrame(AISpawn.CFrame + Vector3.new(0, Height, 0)).
Im not trying to position it since the AISpawn is already positioned properly for the NPC to be teleported to. Im trying to recalculate the hip height so the NPC legs don’t fall through the ground
I know they were wrong which is why i changed them to this
function recalculateHipHeight()
--if r15
local character = script.Parent.Parent
local bottomOfHumanoidRootPart = character.HumanoidRootPart.Position.Y - (1/2 * character.HumanoidRootPart.Size.Y)
local bottomOfFoot = character.LeftFoot.Position.Y - (1/2 * character.LeftFoot.Size.Y)
local newHipHeight = bottomOfHumanoidRootPart - bottomOfFoot
local humanoid = character:FindFirstChildOfClass("Humanoid")
humanoid.HipHeight = newHipHeight
end
function recalculateHipHeight2()
--if r6
script.Parent.Parent:FindFirstChild("Humanoid").HipHeight = 0
end
Make sure the AISpawn part’s Orientation is (0, 0, 0), and try again. It might be that you’re trying to tilt the humanoids when you’re setting the new CFrames, which humanoids don’t like.
local Players = game:GetService("Players")
local USERNAME = script.Parent.Name
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum = pagenum + 1
end
end)
end
local userId = Players:GetUserIdFromNameAsync(USERNAME)
local friendPages = Players:GetFriendsAsync(userId)
local usernames = {}
for item, pageNo in iterPageItems(friendPages) do
table.insert(usernames, item.Username)
end
for i,v in pairs(usernames) do
local playerid = require(script.Parent.FriendUserID)
print(Players:GetUserIdFromNameAsync(tostring(v)))
table.insert(playerid, Players:GetUserIdFromNameAsync(tostring(v)))
end
local playerid = require(script.Parent.FriendUserID)
This fetches the id then puts them in a modulescript named FriendUserID which is then required from the script above
What happens if you add 1 to the HipHeight when you spawn them in to see if it’s the problem or not?
Another issue might be the Density of the NPC Parts. I’m just guessing here, but I know that having Tools or other items welded to the Player messes up their movements.