Conveyor Rotation Error

Hi, I am currently making a game similar to Tower of Hell and there are 2 scripts that handle the conveyor parts though when a stage is rotated they conveyor no longer conveys the player in the way it was intended to.

Conveyor Scripts:

function Conveyor(O)
	
	if O.Name ~= "Conveyor" then return end
	if not O:IsA("Part") then return end
	if not O.Parent or not O:WaitForChild("Texture") or not O:WaitForChild("Speed") then return end
	
	O.Velocity = O.CFrame.lookVector * O.Speed.Value
end

game.Workspace.DescendantAdded:Connect(Conveyor)

for _, v in pairs(game.Workspace:GetDescendants()) do
	
	Conveyor(v)
end
local RunService = game:GetService("RunService")

function Texture(O)
	
	if O.Name ~= "Conveyor" then return end
	if not O:IsA("Part") then return end
	
	pcall(function()
		
		local Connection = nil
		
		wait()
		
		Connection = RunService.Heartbeat:Connect(function()
			
			if not O then return end
			if not O.Parent or not O:WaitForChild("Texture") or not O:WaitForChild("Speed") then Connection:Disconnect() end
			
			O.Texture.OffsetStudsV = -(game.Workspace.DistributedGameTime * O.Speed.Value) % O.Texture.StudsPerTileV
		end)
	end)
end

game.Workspace.DescendantAdded:Connect(Texture)

for _, v in pairs(game.Workspace:GetDescendants()) do
	
	Texture(v)
end

Script that manages the stage rotations:

Debounce = false

function NewTower()

	Debounce = true

	Floor1 = Stages[math.random(1, #Stages)]:Clone()
	Floor1.Parent = Tower
	Floor1.PrimaryPart = Floor1:FindFirstChild("Center")
	Floor1:SetPrimaryPartCFrame(Floor1.Center.CFrame)
	local Floor1Height = Floor1.Height.Value
	wait()

	Floor2 = Stages[math.random(1, #Stages)]:Clone()
	Floor2.Parent = Tower
	Floor2.PrimaryPart = Floor2:FindFirstChild("Center")
	Floor2:SetPrimaryPartCFrame(Floor1.Center.CFrame + Vector3.new(0, Floor1Height, 0))
	Floor2:SetPrimaryPartCFrame(Floor2.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor2Height = Floor2.Height.Value
	wait()

	Floor3 = Stages[math.random(1, #Stages)]:Clone()
	Floor3.Parent = Tower
	Floor3.PrimaryPart = Floor3:FindFirstChild("Center")
	Floor3:SetPrimaryPartCFrame(Floor2.Center.CFrame + Vector3.new(0, Floor2Height, 0))
	Floor3:SetPrimaryPartCFrame(Floor3.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor3Height = Floor3.Height.Value
	wait()

	End.PrimaryPart = End:WaitForChild("Center")
	End:SetPrimaryPartCFrame(Floor3.Center.CFrame + Vector3.new(0, Floor3Height), 0)
	End:SetPrimaryPartCFrame(End.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	Debounce = false

	TowerHeight.Value = Floor1Height + Floor2Height + Floor3Height + 30 * 2
	ReplicatedStorage.Events.HeightEvent:FireAllClients(TowerHeight.Value)
end
1 Like

You could maybe add a int value inside of the stages when cloning them, their value would be 180 or the other rotation angle depending on the cloning, then if the value is 180, then for example the velocity of the conveyor would be O.Velocity = O.CFrame.lookVector * O.Speed.Value and for the other angle, it would be O.Velocity = O.CFrame.lookVector * -O.Speed.Value

1 Like

Thanks for helping, though could you clarify a bit more on the int values needed inside the stage script?

(This is the rotation I’m talking about)
image

The int values helps determine the rotation of the stage, so if the rotation set by the stage script for the stage is 180, then you set the Int Value you pre-made into the stage to 180, samething for example the angle -180 or 0.

Thanks for explaining it more, though I’m not too sure on how to implement it.

Well first of all, you would insert a int value inside of all of your stages, then in the stage script, you would change the int value to the rotation of the stage you’re cloning.

For example:

	Floor3 = Stages[math.random(1, #Stages)]:Clone()
	Floor3.Parent = Tower
	Floor3.PrimaryPart = Floor3:FindFirstChild("Center")
	Floor3:SetPrimaryPartCFrame(Floor2.Center.CFrame + Vector3.new(0, Floor2Height, 0))
	Floor3:SetPrimaryPartCFrame(Floor3.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor3Height = Floor3.Height.Value
    Floor3.RotationValue.Value = 180 -- It would be 180 because the math.rad above is 180
	wait()

image

1 Like

Alright thanks I’ll test this.

Alr, sorry if I’m bad at explaining :sweat_smile:

It’s okay, I understand visuals more than text. Though I have one more problem, how exactly could I get the conveyor script to find the int values in each stage?

Well you would do this “An example”:

local Stage = -- Find the stage using O.Parent or O.Parent.Parent ...
local RotationV = Stage:FindFirstChild("RotationValue")
if RotationV.Value == 180 then
   O.Velocity = O.CFrame.lookVector * O.Speed.Value
else
   O.Velocity = O.CFrame.lookVector * -O.Speed.Value
end
1 Like

This isn’t nessasarily related, but you seem to be using a lot of values. Have you tried attributes?
Learn how to use attributes at Instance Attributes.

1 Like

I don’t see the difference in using attributes, all it does is make it cleaner, but a bit harder to understand.

Thanks the conveyors work properly now. This isn’t necessary but is there a way to make it detect the stage if the conveyors were to be put in extra models?

I wouldn’t say harder to understand. I think they’re much neater. They’re part of the Instance themselves, so you also don’t have to wait for them to replicate. You can change them right in the Properties tab of the Instance too.

ValueBases are mostly a legacy thing.

Make extra checks to see if the parent that defines the stage is different (example):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
if ReplicatedStorage:FindFirstChild(O.Parent.Name) then
-- -- Code
elseif ReplicatedStorage:FindFirstChild(O.Parent.Parent.Name) then
-- Code
end

I understand what you’re saying, but if I were that person, I wouldn’t take extra time to make use of the feature, because of how little difference it makes.

Which codes goes where with the extra checks being added?

You need to add it to the conveyor function

I know that but how do I format it?