Character Sliding [NPC]

  1. What do you want to achieve?
    An AI that doesn’t slide around the ground :slight_smile:

  2. What is the issue?
    The Character is Sliding and I don’t have any idea how to fix it.

  3. What solutions have you tried so far?
    I did look on the DevHub but didn’t find anything,
    I tried changing the HipHeight
    Changing Platform Stand to true [Made it worse so I changed it back]
    Setting all the parts to CanCollide = false

Currently the HumanoidRootPart is not anchored like every other Part, Otherwise it wouldn’t move.

Also Here’s the AI Code:

local teddy = script.Parent
local humanoid = teddy.Humanoid

local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection

humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)

for i, player in ipairs(game.Players:GetPlayers()) do
	script.Parent.HumanoidRootPart:SetNetworkOwner(player)
end

local PathfindingService = game:GetService("PathfindingService")

local function getPath(destination)
	local pathParams = {
		["AgentHeight"] = 3,
		["AgentRadius"] = 1.5,
		["AgentCanJump"] = true,
		["AgentCanClimb"] = true,
	}


	local path = PathfindingService:CreatePath(pathParams)
	
	for _, part in pairs(script.Parent:GetChildren()) do 
		if part:IsA("BasePart") then 
			part:SetNetworkOwner(nil) 
		end
	end

	local waypointss = path:GetWaypoints()
	--
	path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)

	path.Blocked:Connect(function()
		print("Path is blocked, Generating new Path..")
		path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)
	end)



	--

	for _, part in pairs(script.Parent:GetChildren()) do 
		if part:IsA("BasePart") then 
			part:SetNetworkOwner(nil) 
		end
	end


	return path

end

local function walkTo(destination)
	local path = getPath(destination)

	for _, part in pairs(script.Parent:GetChildren()) do 
		if part:IsA("BasePart") then 
			part:SetNetworkOwner(nil) 
		end
	end


	for index, waypoint in pairs(path:GetWaypoints()) do
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
end

local function patrol()
	for _, part in pairs(script.Parent:GetChildren()) do 
		if part:IsA("BasePart") then 
			part:SetNetworkOwner(nil) 
		end
	end

	local waypoints = workspace.IMPORTANTSCRIPTING.TrashRobotSpots:GetChildren()
	local randomNum = math.random(1, #waypoints)
	walkTo(waypoints[randomNum])
end

local Anims = script.Parent.Anims.Uploaded

local Spots = game.Workspace.IMPORTANTSCRIPTING.TrashRobotSpots

local Torso = script.Parent.Torso

local Root = script.Parent.HumanoidRootPart

local Sounds = script.Parent.Head.Sounds

wait(1)

patrol()

while wait(3) do
	if script.Parent.Scripting.IsInTalk.Value == 0 then
		local Randomizer = math.random(1,5)
		if Randomizer == 1 then
			walkTo(Spots.Trash1)
			wait(0.2)
			Torso.CFrame = Spots.Trash1.CFrame
			Root.Anchored = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Play()
			Sounds.TrashMotor:Play()
			wait(2)
			Spots.Trash1.Icosphere.Transparency = 1
			Sounds.TrashMotor2:Play()
			script.Parent.Head.ProximityPrompt.Enabled = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Stop()
			Root.Anchored = false
			wait(7)
			Spots.Trash1.Icosphere.Transparency = 0
		
			script.Parent.Head.ProximityPrompt.Enabled = false
		end
		if Randomizer == 2 then
			walkTo(Spots.Trash2)
			wait(0.2)
			Torso.CFrame = Spots.Trash2.CFrame
			Root.Anchored = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Play()
			Sounds.TrashMotor:Play()
			wait(2)
			Root.Anchored = false
			Spots.Trash2.Icosphere.Transparency = 1
			Sounds.TrashMotor2:Play()
			script.Parent.Head.ProximityPrompt.Enabled = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Stop()
			wait(7)
		
			Spots.Trash2.Icosphere.Transparency = 0
			script.Parent.Head.ProximityPrompt.Enabled = false
		end
		if Randomizer == 3 then
			walkTo(Spots.Trash3)
			wait(0.2)
			Torso.CFrame = Spots.Trash3.CFrame
			Root.Anchored = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Play()
			Sounds.TrashMotor:Play()
			wait(2)
			Root.Anchored = false
			Spots.Trash3.Icosphere.Transparency = 1
			Sounds.TrashMotor2:Play()
			script.Parent.Head.ProximityPrompt.Enabled = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Stop()
			wait(7)

			Spots.Trash3.Icosphere.Transparency = 0
			script.Parent.Head.ProximityPrompt.Enabled = false
		end
		if Randomizer == 4 then
			walkTo(Spots.Trash4)
			wait(0.2)
			Torso.CFrame = Spots.Trash4.CFrame
			Root.Anchored = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Play()
			Sounds.TrashMotor:Play()
			wait(2)
			Root.Anchored = false
			Spots.Trash4.Icosphere.Transparency = 1
			Sounds.TrashMotor2:Play()
			script.Parent.Head.ProximityPrompt.Enabled = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Stop()
			wait(7)
	
			Spots.Trash4.Icosphere.Transparency = 0
			script.Parent.Head.ProximityPrompt.Enabled = false
		end
		if Randomizer == 5 then
			walkTo(Spots.Trash5)
			wait(0.2)
			Torso.CFrame = Spots.Trash5.CFrame
			Root.Anchored = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Play()
			Sounds.TrashMotor:Play()
			wait(2)
			Root.Anchored = false
			Spots.Trash5.Icosphere.Transparency = 1
			Sounds.TrashMotor2:Play()
			script.Parent.Head.ProximityPrompt.Enabled = true
			script.Parent.Humanoid:LoadAnimation(Anims.CollectTrash):Stop()
			wait(7)

			Spots.Trash5.Icosphere.Transparency = 0
			script.Parent.Head.ProximityPrompt.Enabled = false
		end
		
	else
		print("Not Available cuz Talking to Player!")
	end

end



Maybe you can Help :smiley:

3 Likes

Could you tell me what the ‘Scale’ property of the NPC’s ‘Model’ is?

1 Like

I Checked it says: It’s Scale is::

0.006

1 Like

Alright, could you put all of the contents/children of that ‘Model’ and put it into a new ‘Model’? You can re-name it back to the same thing, just everything needs to be grouped/put into a new ‘Model’.

I want to check if that’ll fix the issue. If what I explained doesn’t make sense, I could provide a video.

3 Likes

As long as my Rig Stays thats okay.
Im gonna try it now.

Haven’t thought it would be that easy!
Thanks It Worked!

1 Like

No problem. There’s currently an issue regarding the ‘Scale’ property for custom character models. Something about physics and whatnot. Roblox knows about it.

To anyone who stumbles upon this, make sure your Humanoid ‘HipHeight’ is high enough and that the ‘Scale’ property is 1 for your custom characters ‘Model’.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.