Moving textures are the same speed, don't move the same speed

I’m currently working on a game similar to “the infinite road trip” and “bus simulator”, which are just social hangouts on vehicles that just drive with periodic pauses. I’m also using the way “the infinite road trip” makes their illusion that the car is moving. Moving textures, conveyers, death parts and ragdoll. This would make it so if you jumped off the car, you would die, ragdoll and be left behind using the conveyers going the same speed as the texture.

The problem with doing this, you can’t really have both a fast and smooth texture. It’s either fast and harsh or slow and smooth. I need it smooth and fast, but I’m trying to figure out why fast and smooth isn’t an option. And after some testing I made a video. If you do the math, the scripts show that every 0.1 second the textures should offset by 1, and the textures should move essentially the same as each other except the amount it’s moving at a time. If you watch the video you can see that it doesn’t work like that. Can someone tell me why and/or how I could fix this?

robloxapp-20231213-1945005.wmv (6.3 MB)

-- This code moves the top one.

local part = script.Parent

local function changeOffsetStudsU()
	local texture = part.Texture
	if not texture then
		return
	end

	local currentOffset = texture.OffsetStudsU
	texture.OffsetStudsU = currentOffset + 0.5
end

while true do
	changeOffsetStudsU()
	wait(0.05)
end
-- This code moves the middle one.

local part = script.Parent

local function changeOffsetStudsU()
	local texture = part.Texture
	if not texture then
		return
	end

	local currentOffset = texture.OffsetStudsU
	texture.OffsetStudsU = currentOffset + 0.25
end

while true do
	changeOffsetStudsU()
	wait(0.025)
end
-- This code moves the bottom one.

local part = script.Parent

local function changeOffsetStudsU()
	local texture = part.Texture
	if not texture then
		return
	end

	local currentOffset = texture.OffsetStudsU
	texture.OffsetStudsU = currentOffset + 0.1
end

while true do
	changeOffsetStudsU()
	wait(0.01)
end

You should be using task.wait for more accurate timing. Your math is also incorrect because for example, in one of your scripts, you’re offsetting the texture by 0.1, but then you’re waiting for 0.01. If you made the increment and wait time the same, it should be the same speed as any other one.

You can also use task.wait()'s return value, which is how much time has elapsed. This also allows the speed to remain constant, not being dependent on FPS.

Code:

local part = script.Parent

local speed = 1

local function changeOffsetStudsU()
	local texture = part.Texture

	local currentOffset = texture.OffsetStudsU
	texture.OffsetStudsU = currentOffset + task.wait() * speed
end

while true do
	changeOffsetStudsU()
end
1 Like