Categories > Coding > Lua >

How to tween tp and do this fuction

Posts: 17

Threads: 10

Joined: Sep, 2022

Reputation: 0

Posted

Aight so, I need to make a script which tween tps to a place and holds e for 4 seconds (in order to get a weapon) and tp back to the orginal place

with the click of an button, No need to put mouse function im using rayfield hub and using the inbuilt button script

 

Colour coded so you can understand better.

Red=Not important

Blue=Main

Green=Minor Details

Purple=Major Details.

  • 0

Haruka

STD Testing Center

Posts: 53

Threads: 3

Joined: Feb, 2023

Reputation: 5

Replied

local player = game.Players.LocalPlayer
local originalPosition = player.Character.HumanoidRootPart.Position

local destination = Vector3.new(10, 5, 0) -- replace with your desired destination

local tweenInfo = TweenInfo.new(
    2, -- duration in seconds
    Enum.EasingStyle.QuadInOut,
    Enum.EasingDirection.InOut,
    0, -- number of times to repeat (0 means play once)
    false, -- should the tween reverse back to the start?
    0 -- delay before starting
)

local tween = game:GetService("TweenService"):Create(player.Character.HumanoidRootPart, tweenInfo, {
    Position = destination
})

tween:Play()

wait(2) -- wait for the tween to complete

player.Character.HumanoidRootPart.CFrame = CFrame.new(destination) -- set the position to the destination

-- simulate pressing the 'e' key for 4 seconds
local eKeyDown = false
local function pressE()
    if not eKeyDown then
        eKeyDown = true
        game:GetService("UserInputService"):KeyDown(Enum.KeyCode.E)
        wait(4)
        game:GetService("UserInputService"):KeyUp(Enum.KeyCode.E)
        eKeyDown = false
    end
end
coroutine.wrap(pressE)()

local returnTweenInfo = TweenInfo.new(
    2, -- duration in seconds
    Enum.EasingStyle.QuadInOut,
    Enum.EasingDirection.InOut,
    0, -- number of times to repeat (0 means play once)
    false, -- should the tween reverse back to the start?
    0 -- delay before starting
)

local returnTween = game:GetService("TweenService"):Create(player.Character.HumanoidRootPart, returnTweenInfo, {
    Position = originalPosition
})

returnTween:Play()

wait(2) -- wait for the return tween to complete

player.Character.HumanoidRootPart.CFrame = CFrame.new(originalPosition) -- set the position back to the original

 

  • 0

https://media.discordapp.net/attachments/979069297374671018/1078367228593971362/VelvetSiggy.png

 

 

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )