Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I freeze a player, disable input?

Asked by 5 years ago
Edited 5 years ago

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)
0
Disabling player input depends on what you're doing. If you are doing some kind of mario kart racing then you would need to use the input that controls the vehicle. If not, ContextActionService might be able to help you. Instead of Touched event use Region3 or Raycast to detect the player. xPolarium 1388 — 5y
0
Then you can use Lerp to have the character smoothly move to their new location. xPolarium 1388 — 5y
0
i mean, you can use a bodyPosition and a body gyro or set their walkspeed & jumppower to 0 theking48989987 2147 — 5y
View all comments (3 more)
0
game:GetService("Players")[playername].Character.HumanoidRootPart.Anchored = true User#24895 0 — 5y
0
So, what I have done is create a baseplate that is invisible to the players that when they fall and land on it, a part is created as a Seat, then the player is Seat:Sit to it. From there I think I am going to add a BodyPosition to the seat and Lerp over time vertically, then laterally over the place they "fell" off the platform once above the original position, break the weld and destroy the seat Karl_Poppa 11 — 5y
0
if you want their orientation to stay constant, use a bodygyro as well theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Answer this question