I have this script in a part, but it doesn’t seem to be working. There’s no errors and I’m very stuck.
task.wait(4)
local characters = workspace.CharactersInGame:GetChildren()
local character = nil
local root = nil
local module = {}
local Rep = game:GetService("ReplicatedStorage")
local moving = false
function module.MoveTo(Part, Part2)
local waypoints = workspace:WaitForChild("Map"):WaitForChild("Waypoints")
local function Move(waypoint, sphere)
moving = true
local currentPosition = sphere.Position
local designatedPosition = waypoint.Position
local cPositionX = sphere.Position.X -- current
local cPositionY = sphere.Position.Y
local cPositionZ = sphere.Position.Z
repeat
task.wait()
sphere.CFrame = CFrame.new(sphere.Position, waypoint.Position)
local dPositionX = designatedPosition.X -- designated
local dPositionY = designatedPosition.Y
local dPositionZ = designatedPosition.Z
if cPositionX < dPositionX then
sphere.Position += Vector3.new(1, 0, 0)
elseif cPositionX > dPositionX then
sphere.Position -= Vector3.new(1, 0, 0)
end
if cPositionY < dPositionY then
sphere.Position += Vector3.new(0, 1, 0)
elseif cPositionY > dPositionY then
sphere.Position -= Vector3.new(0, 1, 0)
end
if cPositionZ < dPositionZ then
sphere.Position += Vector3.new(0, 0, 1)
elseif cPositionZ > dPositionZ then
sphere.Position -= Vector3.new(0, 0, 1)
end
currentPosition = sphere.Position
designatedPosition = waypoint.Position
cPositionX = currentPosition.X
cPositionY = currentPosition.Y
cPositionZ = currentPosition.Z
dPositionX = designatedPosition.X
dPositionY = designatedPosition.Y
dPositionZ = designatedPosition.Z
until (currentPosition - designatedPosition).Magnitude < 2
moving = false
print("finished")
end
while task.wait() do
if (Part2.Position - Part.Position).Magnitude < 1 then return end
for index, waypoint in pairs(waypoints:GetChildren()) do
if (waypoint.Position - Part2.Position).Magnitude < 2 then
if not moving then Move(waypoint, script.Parent) end
end
end
end
end
while task.wait(8) do
characters = workspace.CharactersInLobby:GetChildren()
character = characters[math.random(1, #characters)]
root = character:WaitForChild("HumanoidRootPart")
module.MoveTo(script.Parent, root)
print("move")
end
I was using a module script before, but completely forgot to just make a regular function in the script after I copied and pasted the code. I can change the way it is to make it in a function if that helps in any possible way.
it still should work correctly if its in a server script. It seems that something must be yielding the entire script. Try putting print("blah blah blah") in places and see where in the script its having the problem.
20:55:16.115 Workspace.BotSphere.FloatToPoint:85: invalid argument #2 to 'random' (interval is empty) - Server - FloatToPoint:85
20:55:16.121 Stack Begin - Studio
20:55:16.122 Script 'Workspace.BotSphere.FloatToPoint', Line 85 - Studio - FloatToPoint:85
20:55:16.122 Stack End - Studio
My player.Character is in the folder though, which confuses me.
The part’s supposed to be anchored, becuase if it wasn’t, it would have rolled away and would keep trying to roll away between the time’s of when the Move() function is fired.
This is error is basically saying that workspace.CharactersInLobby:GetChildren() is equal to 0 or nil, maybe run some tests and see why? also, make sure the characters are being put inside the folder on the server side.
I don’t know if this will help you any in moving your parts, but I created this place to help with another post. However it uses CFrames and Tweening to move the door open and closed. AutomaticSlidingDoor.rbxl (41.4 KB)
And this other place file, for yet another post, where they needed an object to follow a set of waypoints. FollowWaypoints.rbxl (74.4 KB)
Maybe something in there can help you.
Sorry I couldn’t do more.