Ad
Log in to vote
0

How to tween character transparency? (preferably on keybind)

Asked by
pr3cure -26
17 days ago

Hello! So i am trying to make a code so that when the character teleports, their transparency fades out for a few seconds, then comes back. I am trying to tween the players transparency in player visiblity so it smoothly goes from 0-1-0, im super new to coding so bare with me. I want it to be connected to the teleport function like the other tweens so when you press the keybind it all happens at once, any help on what im doing wrong? or what i should do? Please and thank you! I've been looking all day. (note i just cut off the other codes for the tweens, i just copied the player visiblity cause its what im struggling with)

```~~~~~~~~~~~~~~~~~

-- PLAYER VISIBLITY --
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local children = char:GetChildren()
local trtweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local trtween = game:GetService("TweenService")

for i, child in ipairs(children) do
    if child:IsA("BasePart") or child:IsA("MeshPart") then
        if child.Transparency == 0 then
            trtween:Create(child, trtweenInfo, {Transparency = 1,0}):Play()
        end
    end
end

-- TELEPORTATION -- these can be used on their owns individually
wait()
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Range = 300
Mouse.KeyDown:Connect(function(key)
    local MousePosition = Mouse.Hit.Position
    local Distance  = (Player.Character.Head.Position - MousePosition).Magnitude
    if key == "t" and Distance <= Range then
        print("T was pressed")
        Tween:Play()
        TweenLight:Play()
        wait(1)
        Player.Character:MoveTo(MousePosition)
        Regular:Play()
        TweenLightDef:Play()
    end
end)

~~~~~~~~~~~~~~~~~ ```

1 answer

Log in to vote
0
Answered by
boredlake 171
17 days ago

To use TweenService, you only put one goal value for each property that you are tweening, and for Transparency, that would only be one number, not two. So, you should put:

trtween:Create(child, trtweenInfo, {Transparency = 1}):Play()

Since you have set Enum.EasingDirection to InOut, it will go from 0 to 1 and back to 0, like you want it to.

0
Ah okay, thank you! If i wanted to turn it into a keybind how would i? when i try to do "trtween:play()" the ":play()" doesnt show up. I tried turning the trtween into a variable like "local transparent tween = trtween:Create(child, trtweenInfo, {Transparency = 1}):Play()" but it still doesn't show up when i try to play it. This only happens when i try to play it on a line separate from the trtwee pr3cure -26 — 17d
Ad

Answer this question