So I'm making a PBB trainer battle style thing, and when you walk in front of a trainer, I want it to wave and then walk towards you. It's waving, but it takes like 20 seconds to walk towards you after that. Here is my code:
function module:WalkTo(model, point, speed)
if not model then return end
local root = model:FindFirstChild('HumanoidRootPart')
local humanoid = model:FindFirstChild('Humanoid')
if not root then return end
local prespeed = humanoid.WalkSpeed
humanoid.WalkSpeed = speed or humanoid.WalkSpeed
local initialDirection = ((point-root.Position)*flat).Unit
while true do
local direction = ((point-root.Position)*flat).Unit
if math.deg(math.acos(direction:Dot(initialDirection))) > 80 then break end
if not humanoid or not humanoid.Parent then return end
print("Moving")
humanoid:Move(direction)
runService.RenderStepped:Wait()
end
humanoid:Move(Vector3.zero)
humanoid.WalkSpeed = prespeed
end
while true do
wait()
for i, v in pairs(trainers) do
raycastparams.FilterDescendantsInstances = { v }
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
local raycast = workspace:Raycast(v.HumanoidRootPart.Position, v.HumanoidRootPart.CFrame.LookVector*100, raycastparams)
if raycast then
if raycast.Instance.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Events.SetPlayerMovespeed:FireServer(0, "code")
local animToPlay = v.Humanoid.Animator:LoadAnimation(script.Parent.WaveAnimation)
animToPlay:Play()
local playerPos = raycast.Instance.Parent.PrimaryPart.Position
print(playerPos)
wait()
module:WalkTo(v, playerPos, 16)
module:say(require(v.Interact).lines, game.Players.LocalPlayer:GetMouse(), v, false, true, v)
end
end
end
end
Any help?
