Hello,
So I have these 2 rigs I want them to stop at the centre of the stoppart not stop immediately when it has touched the stoppart no matter what I have tried hasn’t worked for me so far hopefully someone from here could assist me.
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local retroFolder = Workspace:WaitForChild("RetroSlops")
local notRetroFolder = Workspace:WaitForChild("NotRetroSlops")
local spawnPart = Workspace:WaitForChild("SpawnPart")
local stopPart = Workspace:WaitForChild("StopPart")
local function addAnimate(rig)
local humanoid = rig:FindFirstChild("Humanoid")
if not humanoid then return end
local animator = humanoid:FindFirstChildOfClass("Animator")
if not animator then
animator = Instance.new("Animator")
animator.Parent = humanoid
end
local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "http://www.roblox.com/asset/?id=180435571"
local idleTrack = animator:LoadAnimation(idleAnim)
local walkAnim = Instance.new("Animation")
walkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
local walkTrack = animator:LoadAnimation(walkAnim)
idleTrack:Play()
humanoid.Running:Connect(function(speed)
if speed > 0 then
if not walkTrack.IsPlaying then
idleTrack:Stop()
walkTrack:Play()
end
else
if not idleTrack.IsPlaying then
walkTrack:Stop()
idleTrack:Play()
end
end
end)
end
local function spawnRig()
local chosenFolder = math.random(1,2) == 1 and retroFolder or notRetroFolder
local rig = chosenFolder:GetChildren()[1]
if not rig then
warn("No rig found in chosen folder")
return
end
local newRig = rig:Clone()
newRig.Parent = Workspace
local hrp = newRig:WaitForChild("HumanoidRootPart")
local humanoid = newRig:WaitForChild("Humanoid")
hrp.Anchored = false
humanoid.WalkSpeed = 4
humanoid.AutoRotate = true
addAnimate(newRig)
hrp.CFrame = CFrame.new(spawnPart.Position + Vector3.new(0, hrp.Size.Y/2, 0))
local stopCenter = stopPart.Position + Vector3.new(0, stopPart.Size.Y/2, 0)
humanoid:MoveTo(stopCenter)
local conn
conn = RunService.Heartbeat:Connect(function()
local distance = (hrp.Position - stopCenter).Magnitude
if distance < 0.5 then
conn:Disconnect()
humanoid:Move(Vector3.new(0,0,0), false)
humanoid.PlatformStand = true
humanoid.AutoRotate = false
hrp.Anchored = true
hrp.CFrame = CFrame.new(stopCenter)
local currentLook = hrp.CFrame.LookVector
local rightLook = Vector3.new(currentLook.Z, 0, -currentLook.X)
hrp.CFrame = CFrame.new(stopCenter, stopCenter + rightLook)
for _, part in ipairs(newRig:GetDescendants()) do
if part:IsA("BasePart") and part ~= hrp then
local weld = Instance.new("WeldConstraint")
weld.Part0 = hrp
weld.Part1 = part
weld.Parent = part
end
end
end
end)
end
spawnRig()