Code not working (Still unsolved)

I want to make a character move along a road for a TD game and I am using GnomeCode’s script for this. The issue is that before reaching every checkpoint my character drifts to the side significantly before correcting it’s course about half way through. This technically works but looks ugly and I would much rather it actually gets to the intended destination directly. In an attempt to remedy the problem I have about 20 nodes on a short path but the problem persists.

Code:

local character = script.Parent
local waypoints = workspace.Nodes

for waypoint=1, #waypoints:GetChildren() do
	character.Humanoid:MoveTo(waypoints[waypoint].Position)
	character.Humanoid.MoveToFinished:Wait()
end

1 Like

You can try to use tween instead. Personally I like it better since MoveTo is… sub-par.

local ts = game:GetService("TweenService")
local character = script.Parent
local waypoints = workspace.Nodes

for waypoint=1, #waypoints:GetChildren() do
	local twn = ts:Create(character.HumanoidRootPart,TweenInfo.new(1,Enum.EasingStyle.Cubic, Enum.EasingDirection.Out),{CFrame = CFrame.new(waypoints[waypoint+1],waypoints[waypoint+2])}) 
        twn:Play()
        twn.Completed:Wait()
end

Not tested for errors though.

1 Like

It says “TweenInfo.new second argument expects Enum.EasingStyle input”

Worth a shot. Wanted to see if you could index the easingdirection enum with a string (edited)

You should be able to! Must’ve been a typo?

I just reentered it and it says “Workspace.Growth.Movement:6: invalid argument #1 to ‘new’ (Vector3 expected, got Instance)”
*Growth is the character

Are you able to supply a video of what is occurring? Then we could better assist you.

You need to do the position of the waypoint rather than just the waypoint. It is attempting to create a CFrame out of instances, where you need to create it from the position of the instance.

I am attempting to take a video but now for some reason my parts of my model are disappearing randomly

I think roblox has crashed (or something on my end) because studio has just crashed and I cannot open it or roblox

Roblox is currently down. 30char!

I will add a video once it goes back up

1 Like

Why is roblox always down haha

It will probably last a few minutes to an hour at most. It’s rarely down…

It seems to already be somewhat working as studio has started loading for me

nope its still down it just crashed at the main screen

So to confirm would I change:

To:

{CFrame = CFrame.new(waypoints[waypoint+1].Position,waypoints[waypoint+2].Position)})

Thanks for your help but I will need a minute to set this back up bc when roblox shut down the entire place wiped

I am now incredibly confused. I am using the code:

local ts = game:GetService("TweenService")
local character = script.Parent
local waypoints = workspace.Nodes

for waypoint=1, #waypoints:GetChildren() do
	local twn = ts:Create(character.HumanoidRootPart,TweenInfo.new(1,Enum.EasingStyle.Cubic, Enum.EasingDirection.Out),{CFrame = CFrame.new(waypoints[waypoint+1].Position,waypoints[waypoint+2].Position)}) 
	twn:Play()
	twn.Completed:Wait()
end

Whenever I run this code the character zooms BACKWARDS at an incredible speed. I have made sure the root part is facing forwards. I was going to attach a video but xbox game bar decided to just not launch so I cannot but it takes about 4 seconds for the character to get out of eyesight, which I assume is the edge of the baseplate

Here is a picture of the map itself:

And here is the log (I doubt it will matter but might as well include it)

16:53:05.553 7 is not a valid member of Folder “Workspace.Nodes” - Server - Movement:6
16:53:05.553 Stack Begin - Studio
16:53:05.553 Script ‘Workspace.Growth.Movement’, Line 6 - Studio - Movement:6
16:53:05.553 Stack End - Studio

1 Like

Update: The character no long launches backward at the speed of light. It now moves between the checkpoints but there is a series of other problems. It turns to face the next node as it is moving. Example: it is moving between nodes 3 and 4. While it moves it is constantly rotating until it is in a position that faces node 5 as it reaches node 4, and so on. The other problem is that it moves between the nodes in 5 seconds (changed from the 1 I had previously) no matter than distance, and it eases between the 2. I need to fix all these problems but I am unfamiliar with TweenService and honestly have no idea where to begin.
Edit: I also want the character to move fairly slow, about 6-8 walkspeed if it was using moveTo

Code:

local ts = game:GetService("TweenService")
local character = script.Parent
local waypoints = workspace.Nodes

for waypoint=1, #waypoints:GetChildren() do
	local twn = ts:Create(character.HumanoidRootPart,TweenInfo.new(5,Enum.EasingStyle.Cubic, Enum.EasingDirection.Out),{CFrame = CFrame.new(waypoints[waypoint+1].Position,waypoints[waypoint+2].Position)}) 
	twn:Play()
	twn.Completed:Wait()
end

I also forgot to mention that when it reaches node 5 (out of 6) it just stops moving and says in output:

17:51:17.984 7 is not a valid member of Folder “Workspace.Nodes” - Server - Movement:6
17:51:17.985 Stack Begin - Studio
17:51:17.985 Script ‘Workspace.Growth.Movement’, Line 6 - Studio - Movement:6
17:51:17.985 Stack End - Studio

Note: The previous problem was with my model’s hitbox glitching as far as I can tell