-
I Need: A Moving part that goes back and forth, specificly for a character to hit a door and go backwards a few times.
-
Issue: The Part just moves instantly and then flies below the map. without dissapearing
-
Ive Tried:
Checking Cframe related Parts of the script
checking for typos
doing any of these just makes the whole part stay in place.
The Script:
local RunService = game:GetService("RunService")
local Val = game.ServerScriptService
local Aval = Val.CurrentRoom
local npc = script.Parent
npc.RushNew.CFrame = workspace.Things.Back.CFrame
npc.RushNew.Spawn:Play()
wait(1)
local function Move(MainPart, Update)
local TheEvent = Instance.new("BindableEvent")
local GetUpdated = Update or false
local function GetPlacePosition()
return MainPart.Position
end
local Moving
Moving = RunService.Heartbeat:Connect(function(deltaTime)
local Speed = 400
local PlaceToMove = GetPlacePosition()
local MainPosition = npc.RushNew.Position
local Direction = (PlaceToMove - MainPosition).Unit
local Movin = Speed * deltaTime
local NewMain = MainPosition * Direction * Movin
npc.RushNew.CFrame = CFrame.new(NewMain)
local DistNew = (NewMain - PlaceToMove).Magnitude
if DistNew < 6 then
Moving:Disconnect()
TheEvent:Fire()
end
end)
local NewSignal
if GetUpdated then
NewSignal = Aval.Changed:Connect(function()
MainPart = game.Workspace.Things.Front
end)
end
TheEvent.Event:Wait()
if NewSignal then
NewSignal:Disconnect()
end
end
local Yo = workspace.Things
for i = 0, math.random(1, 10) do
Move(Yo.Front, true)
Move(Yo.Back, false)
end
npc.RushNew:Destroy()
I cannot seem to figure out why the part flies off the map instead of going to the door and back to the first waypoint like its supposed to.
This is the easiest way I’ve known to make something like this. I don’t know what error I’ve Made.
Thanks if anyone can help.