function WaiterWalking()
while NPCSCanWalkValue.Value == true do
if IsLightValue.Value == true then
NightAnim:Stop()
DayAnim:Play()
Humanoid.WalkSpeed = 12
end
if IsLightValue.Value == false then
DayAnim:Stop()
NightAnim:Play()
Humanoid.WalkSpeed = 15
end
local randomPart = math.random(1, 8)
local randomWait = math.random(0.2, 1.5)
wait(randomWait)
if randomPart == 1 then
Humanoid:MoveTo(Part1.Position)
Humanoid.MoveToFinished:Wait()
end
if randomPart == 2 then
Humanoid:MoveTo(Part2.Position)
Humanoid.MoveToFinished:Wait()
end
if randomPart == 3 then
Humanoid:MoveTo(Part3.Position)
Humanoid.MoveToFinished:Wait()
end
if randomPart == 4 then
Humanoid:MoveTo(Part4.Position)
Humanoid.MoveToFinished:Wait()
end
if randomPart == 5 then
Humanoid:MoveTo(Part5.Position)
Humanoid.MoveToFinished:Wait()
end
if randomPart == 6 then
Humanoid:MoveTo(Part6.Position)
Humanoid.MoveToFinished:Wait()
end
if randomPart == 7 then
Humanoid:MoveTo(Part7.Position)
Humanoid.MoveToFinished:Wait()
end
end
end
StartNPCSEvent.Event:Connect(WaiterWalking)
I want DayAnim & NightAnim to play right when IsLight Value is set to true or false.
I know why It doesn’t play right away, and it’s because of the Humanoid.MoveToFinished:Wait(), but I don’t know how else to do it.
If you need more information, just ask!
Any help is appreciated!
This code looks horrendous my guy. Let me fix it a bit:
local PARTS = path.to.partsFolder:GetChildren()
function WaiterWalking()
IsLightValue.Changed:Connect(function()
if IsLightValue.Value == true then
NightAnim:Stop()
DayAnim:Play()
Humanoid.WalkSpeed = 12
end
if IsLightValue.Value == false then
DayAnim:Stop()
NightAnim:Play()
Humanoid.WalkSpeed = 15
end
end)
while NPCSCanWalkValue.Value == true do
local randomPart = PARTS[math.random(1, #PARTS)]
local randomWait = math.random(0.2, 1.5)
wait(randomWait)
Humanoid:MoveTo(SelectedPart.Position)
Humanoid.MoveToFinished:Wait()
end
end
StartNPCSEvent.Event:Connect(WaiterWalking)