I'd like to create a script (onTouch) to freeze a player in place, to be moved by script to a new location, while disabling player input, and then upon touching the new location, re-enable player input and unfreeze. Similar results to a teleport script, but I want to visualize it to the player.... Think the Lakitu player recovery concept from Mario Kart...
Edit: So this is what I've come up with based on everyone's suggestions. I just need some help cleaning up the animation/lerping. It's very choppy; especially if I "Jump" out of the seat manually. I'd like to disable that, but only while being lerped around with my CFrame. This works as is, but I want it to be cleaner.
local debounce = true local tryCount = 0 local lakituModel = game.Workspace.LakituModel local lakituHidingSpot = CFrame.new(Vector3.new(0,-200,0),Vector3.new(0,0,0)) --lakituModel.PrimaryPart = lakituModel:FindFirstChild("Hook") -- Services local userInputService = game:GetService("UserInputService") local players = game:GetService("Players") local function Jump(humanoid) --local humanoid = game.Players.LocalPlayer:FindFirstChild("Humanoid") game.Players.LocalPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, debounce) end local function onTouched(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and debounce then debounce = false local seatObj = Instance.new("Seat") -- Create a seat at the player's position when hitting the baseplate seatObj.Size = Vector3.new(1,1,1) -- Make it small seatObj.Anchored = true -- Make it immovable by physics seatObj.CFrame = CFrame.new(hit.CFrame.p, Vector3.new(0,0,0)) -- Move it to the player seatObj.Transparency = 0 -- Make it invisible seatObj.Parent = workspace -- place it in the world seatObj:Sit(hit.Parent:WaitForChild("Humanoid")) -- Sit the character in the seat to immobilize them -- Do Lakitu Stuff local CFrameX = hit.CFrame.X local CFrameY = hit.CFrame.Y local CFrameZ = hit.CFrame.Z local startPosition = CFrame.new(hit.CFrame.p, Vector3.new(0,0,0)) -- Get the start position of the seat -- get the player to acquire the reset position local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Currently an arbitrary CFrame position at the spawn point, will change to update last part player was standing on before jumping local destinationPosition = CFrame.new(player.PlayerStats.LastPlayerPosition.Value + Vector3.new(0,6,0), Vector3.new(0,0,0)) -- Mid point at right angle from start point and destination local midPosition = CFrame.new(Vector3.new(CFrameX, destinationPosition.Y + 6 ,CFrameZ), Vector3.new(0,0,0)) -- Lerp up and hang out wait(1) -- Move Lakitu above player at midposition lakituModel:SetPrimaryPartCFrame(midPosition) -- Lerp Lakitu down to player for i = 0, 1, 0.05 do lakituModel:SetPrimaryPartCFrame(midPosition:lerp(startPosition,i)) wait() end -- Get Hooked wait(1) -- Lerp player and lakitu up to midposition for i = 0, 1, 0.05 do hit.CFrame = startPosition:lerp(midPosition,i) lakituModel:SetPrimaryPartCFrame(startPosition:lerp(midPosition,i)) wait() end -- Lerp to destination for i = 0, 1, 0.05 do hit.CFrame = midPosition:Lerp(destinationPosition, i) lakituModel:SetPrimaryPartCFrame(midPosition:lerp(destinationPosition,i)) wait() end wait() -- Hide Lakitu from players lakituModel:SetPrimaryPartCFrame(lakituHidingSpot) -- Release from weld and destroy seat part seatObj.Anchored = false if seatObj:FindFirstChild("SeatWeld") then -- May have been destroyed by jumping seatObj:FindFirstChild("SeatWeld"):Destroy() end seatObj:Destroy() debounce = true -- Reset Lakitu for player end end script.Parent.Touched:Connect(onTouched)
So this is what I've come up with based on everyone's suggestions. I just need some help cleaning up the animation/lerping. It's very choppy; especially if I "Jump" out of the seat manually. I'd like to disable that, but only while being lerped around with my CFrame. This works as is, but I want it to be cleaner.
local debounce = true local tryCount = 0 local lakituModel = game.Workspace.LakituModel local lakituHidingSpot = CFrame.new(Vector3.new(0,-200,0),Vector3.new(0,0,0)) --lakituModel.PrimaryPart = lakituModel:FindFirstChild("Hook") -- Services local userInputService = game:GetService("UserInputService") local players = game:GetService("Players") local function Jump(humanoid) --local humanoid = game.Players.LocalPlayer:FindFirstChild("Humanoid") game.Players.LocalPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, debounce) end local function onTouched(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and debounce then debounce = false local seatObj = Instance.new("Seat") -- Create a seat at the player's position when hitting the baseplate seatObj.Size = Vector3.new(1,1,1) -- Make it small seatObj.Anchored = true -- Make it immovable by physics seatObj.CFrame = CFrame.new(hit.CFrame.p, Vector3.new(0,0,0)) -- Move it to the player seatObj.Transparency = 0 -- Make it invisible seatObj.Parent = workspace -- place it in the world seatObj:Sit(hit.Parent:WaitForChild("Humanoid")) -- Sit the character in the seat to immobilize them -- Do Lakitu Stuff local CFrameX = hit.CFrame.X local CFrameY = hit.CFrame.Y local CFrameZ = hit.CFrame.Z local startPosition = CFrame.new(hit.CFrame.p, Vector3.new(0,0,0)) -- Get the start position of the seat -- get the player to acquire the reset position local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Currently an arbitrary CFrame position at the spawn point, will change to update last part player was standing on before jumping local destinationPosition = CFrame.new(player.PlayerStats.LastPlayerPosition.Value + Vector3.new(0,6,0), Vector3.new(0,0,0)) -- Mid point at right angle from start point and destination local midPosition = CFrame.new(Vector3.new(CFrameX, destinationPosition.Y + 6 ,CFrameZ), Vector3.new(0,0,0)) -- Lerp up and hang out wait(1) -- Move Lakitu above player at midposition lakituModel:SetPrimaryPartCFrame(midPosition) -- Lerp Lakitu down to player for i = 0, 1, 0.05 do lakituModel:SetPrimaryPartCFrame(midPosition:lerp(startPosition,i)) wait() end -- Get Hooked wait(1) -- Lerp player and lakitu up to midposition for i = 0, 1, 0.05 do hit.CFrame = startPosition:lerp(midPosition,i) lakituModel:SetPrimaryPartCFrame(startPosition:lerp(midPosition,i)) wait() end -- Lerp to destination for i = 0, 1, 0.05 do hit.CFrame = midPosition:Lerp(destinationPosition, i) lakituModel:SetPrimaryPartCFrame(midPosition:lerp(destinationPosition,i)) wait() end wait() -- Hide Lakitu from players lakituModel:SetPrimaryPartCFrame(lakituHidingSpot) -- Release from weld and destroy seat part seatObj.Anchored = false if seatObj:FindFirstChild("SeatWeld") then -- May have been destroyed by jumping seatObj:FindFirstChild("SeatWeld"):Destroy() end seatObj:Destroy() debounce = true -- Reset Lakitu for player end end script.Parent.Touched:Connect(onTouched)