in my tower obby game, I have heaps of different levels. When the tower is randomly generated, every second level is rotated 180 degrees so that the start and ends of each level lines up.
Each level is a model and gets cloned into workspace to create the tower.
In some levels, I have conveyor belts that moves the player along. The only issue is that for every second level in the tower, if it has conveyor belts, they are reversed, and go the opposite way to what I scripted them to.
The conveyor belts work fine when they are 0 degrees:
However, when flipped 180 degrees the conveyors reverse:
Here is the script that makes the conveyors work:
local addConveyor = function(c)
if c.Name == "CONVEYOR" then
c.Parent.Velocity = c.Parent.CFrame.lookVector * c.Value
end
end
workspace.DescendantAdded:Connect(addConveyor)
for i,v in pairs(workspace:GetDescendants()) do
addConveyor(v)
end
Why could This be happening? The individual parts are not being mirrored, they are simply just rotating around the models primary part, so they shouldn’t be reversing…
What is happening?
I have been building for many years on Studio and never experienced this issue.
Hey there!
I’ve had this same issue, and have also made a post about this.
It’s a really easy fix.
The issue is that when the model is cloned and parented into workspace, the script has added the conveyor velocity before the model was orientated.
To easily fix this, just detect a change in the CFrame of the conveyor, then re-apply the conveyor velocity.
Here is a script fix to it, i also added a memory leak prevention (it may not be needed, but let’s be safe.)
I see that you are using the ToH conveyor script, lol
local conveyors = {}
local addConveyor = function(c)
if c.Name == "CONVEYOR" and conveyors[c] == nil then
c.Parent.Velocity = c.Parent.CFrame.lookVector * c.Value
conveyors[c] = {
Speed = c.Value;
Conveyor = c.Parent;
Connection = c.Parent:GetPropertyChangedSignal("CFrame"):Connect(function()
c.Parent.Velocity = c.Parent.CFrame.lookVector * c.Value
end);
};
end
end
local removeConveyor = function(c)
if c.Name == "CONVEYOR" and conveyors[c] then
if conveyors[c] then
-- Cleaning up connections to prevent memory leaks that can possibly cause the server to crash.
conveyors[c].Connection:Disconnect()
conveyors[c].Connection = nil
conveyors[c].Conveyor:Destroy()
conveyors[c] = nil
end
end
end
workspace.DescendantAdded:Connect(addConveyor)
workspace.DescendantRemoving:Connect(removeConveyor)
for i,v in pairs(workspace:GetDescendants()) do
addConveyor(v)
end
I’ve destroyed items that had connections, and the connections have never been disconnected.
One of my games had a memory leak due to this, and thousands ended up loosing data.
It’s not that memory leaks are impossible, but in this situation, where you just have a connection to a single object, Destroying the connected object should be enough.