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

How do i make a part transparent and untransparent on keybind?

Asked by 4 years ago
Edited 4 years ago

alright i'm stuck on this i don't know a lot of lua but this is the script i have so far (its in a localscript in starterpack)

function Keypress(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.T then
        game.Workspace.Entity_246.Head.Transparency = 0 else
        game.Workspace.Entity_246.Head.Transparency = 1
    end
end

game:GetService("UserInputService").InputBegan:Connect(Keypress)

Thanks for reading

Edit: Also any way to make this local player? i mean like instead of One user its the user who presses t? thanks!

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This might work for you; here is some code I just thought up, so try it out. (localscript)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local object = workspace.Entity_246.Head

mouse.KeyDown:connect(function(key)
if key == "t" then --Key of your choice.
        print("Pressed t")
    object.Transparency = 1 --Set transparency to 1.
end
if key == "r" then --Key of your choice.
        print("Pressed r")
    object.Transparency = 0 --Set transparency to 0.
end
end)

Hope this works, (this might not be exactly what you wanted) feel free to modify this to your use if so.

If you want the localplayer's head to go invisible on keypress, then consider this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "t" then --Key of your choice.
        print("Pressed t")
    player.Character.Head.Transparency = 1 --Set transparency to 1.
end
if key == "r" then --Key of your choice.
        print("Pressed r")
    player.Character.Head.Transparency = 0 --Set transparency to 0.
end
end)

Merry Christmas! :)

0
Thank you SO much this really helped :D merry christmas to you too :D EllaTheFloofyFox 106 — 4y
Ad

Answer this question