Most efficient way to make the player move 10 studs?

Hi, I am working on a sophisticated teleporter, where when you go into a invisible zone it makes you move forward 10 studs then fades you away. for now I want to know the easiest way to make the player move 10 studs. I already have the calculations I just want to know if I should use runservice or any other way.

	for _, teleporter in pairs(group:GetChildren()) do
		if not teleporter:IsA("BasePart") then
			continue
		end
		
		if not teleporter:GetAttribute("Teleport") then
			continue
		end
		
		local direction = teleporter:FindFirstChildOfClass("Attachment")
		local destination = (direction.Axis * STUDS) + teleporter.Position
		
		teleporter = teleporter :: BasePart
		
		teleporter.Touched:Connect(function(otherPart: BasePart) 
			local humanoid = otherPart.Parent:FindFirstChild("Humanoid") :: Humanoid?

			if not humanoid then 
				return 
			end

			if Humanoids[humanoid] then
				return
			end

			coroutine.wrap(function(...)  -- debounce
				Humanoids[humanoid] = true

				task.wait(3)

				Humanoids[humanoid] = nil
			end)()
			
			-- TODO: make player walk 10 studs straight from direction value
			humanoid:MoveTo(destination)
		end) 
	end

Looks fine to me, although making the humanoid walk…
You see people could use their controls to constantly reverse your idea of walking
So…
Force them to walk EVERY HEARTBEAT (Warning: this may be a bad idea)

I know people can use their controls but i’m not focused on that right now, I already have a function to freeze the player. MoveTo requires a service like runservice to work. right now, it’s not working.

That is not true. It might internally (If it did, then I learned something), but nothing on your part.
Call it once, and with no resistance, the character will walk there

1 Like

Oh your right lmao, I think I was thinking about :Move. I tested it like this

			-- TODO: make player walk 10 studs straight from direction value
			print("ABOUT TO START")
			task.wait(0.5)
			print("WALKING")
			humanoid:MoveTo(destination)

Thanks lol that was silly

1 Like

I have a question, should I be using local script or server script to make this? I have a odd feeling that I should use local.

Nope, for moving the humanoid you should DEFINITELY use a server-side script

1 Like

So I would just need to call an event to fire this? I’m very picky with using events

--!strict

--[[
	 Freezes the player and uses the boolean argument for yes or no.
--]]

local ContextActionService = game:GetService("ContextActionService")

local function freezePlayer(boolean)
	if boolean then
		ContextActionService:BindActionAtPriority(
			"FREEZE",
			function() 
				return Enum.ContextActionResult.Sink
			end,
			false,
			Enum.ContextActionPriority.High.Value,
			unpack(Enum.PlayerActions:GetEnumItems())
		)
	else
		ContextActionService:UnbindAction("FREEZE")
	end
end

return freezePlayer

Wait, for disabling movement, use a client-side script.
For making the person walk, use a server-side script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.