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
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