Hello.
So I’m making a referee and I’m using NPC’s to represent the chains crew. I’ve ran into a problem where once the NPC reaches the destination it just decides to fly away. It happens after a couple of attempts. Please help me fix this.
function MoveLos(Z)
local Unit = Pads.TrackPad3.CFrame - Pads.TrackPad3.CFrame.Position
Pads.TrackPad3.CFrame = CFrame.new(Pads.TrackPad3.Position.X,Pads.TrackPad3.Position.Y,Z) * Unit
Models.Referee3.Humanoid:LoadAnimation(Replicated:FindFirstChild('Game').Anims:FindFirstChild('Referee').Chains.Grab):Play()
Models.Referee3.Humanoid:LoadAnimation(Replicated:FindFirstChild('Game').Anims:FindFirstChild('Referee').Chains.Hold):Play()
Models.Referee3.Humanoid.WalkToPoint = Vector3.new(Pads.TrackPad3.Position.X,Pads.TrackPad3.Position.Y,Pads.TrackPad3.Position.Z)
Models.Referee3.Humanoid.MoveToFinished:Connect(function()
Module.CharFace(Models.Referee3)
end)
end
Module:
UT.CharFace = function(Model)
if Model:IsA('Model') then
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local TG = {Orientation = Vector3.new(0,-90,0)}
local TT = TweenService:Create(Model.PrimaryPart, TI, TG):Play()
end
end
I’m not exactly sure, but this probably has something to do with you messing with the Orientation itself. Try changing the CFrame.
UT.CharFace = function(Model)
if Model:IsA('Model') then
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local TG = {CFrame = CFrame.new(Model.PrimaryPart.Position) * CFrame.Angles(0,math.rad(-90),0)}
local TT = TweenService:Create(Model.PrimaryPart, TI, TG):Play()
end
end
If it still flies away, try to anchor and unanchor after.
UT.CharFace = function(Model)
if Model:IsA('Model') then
local TI = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local TG = {CFrame = CFrame.new(Model.PrimaryPart.Position) * CFrame.Angles(0,math.rad(-90),0)}
Model.PrimaryPart.Anchored = true
local TT = TweenService:Create(Model.PrimaryPart, TI, TG):Play()
TT.Finished:Wait()
Model.PrimaryPart.Anchored = false
end
end
Also, I didn’t think about this until now, but some NPC’s tend to have a larger primary parts after moving from their original position, so it might be rotating around that while the primary part stays in the same place.
It stopped flying thank you. But now for sum reason it like teleports the character before tweening it towards the other sideline. Is this a MoveToPoint issue or?
I’ve also ran into a problem where. If the humanoid is traveling too far it just decides to give up and stop moving. Causing me to press the button twice making it 2 trips to get to its destination. How could I fix that?
Oh, I had made a script like this for a TDS game since I also ran into that problem.
repeat
model.Humanoid:MoveTo(pos)
local reached = model.Humanoid.MoveToFinished:Wait()
until reached
So, with your code, it should look like:
function MoveLos(Z)
local Unit = Pads.TrackPad3.CFrame - Pads.TrackPad3.CFrame.Position
Pads.TrackPad3.CFrame = CFrame.new(Pads.TrackPad3.Position.X,Pads.TrackPad3.Position.Y,Z) * Unit
Models.Referee3.Humanoid:LoadAnimation(Replicated:FindFirstChild('Game').Anims:FindFirstChild('Referee').Chains.Grab):Play()
Models.Referee3.Humanoid:LoadAnimation(Replicated:FindFirstChild('Game').Anims:FindFirstChild('Referee').Chains.Hold):Play()
repeat
Models.Referee3.Humanoid:MoveTo(Vector3.new(Pads.TrackPad3.Position.X,Pads.TrackPad3.Position.Y,Pads.TrackPad3.Position.Z))
local reached = Models.Referee3.Humanoid.MoveToFinished:Wait()
until reached
Module.CharFace(Models.Referee3)
end
Yes, it is best to make it client based so it replicates better and the server has less strain. You shoulda also probably use CharFace on the client as well. You can eventually set the position on the server so everyone can see it.
I would just copy over all the variables and services and just do it the same way correct? or would I have to change anything. I’ll show you the script if I need too
function MoveIncrements(Yards)
if Values.Flipped.Value then
MoveLos(Pads.TrackPad3.Position.Z - Yards)
else
MoveLos(Pads.TrackPad3.Position.Z + Yards)
end
end
--