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

How to find and set player`s mask invisible?

Asked by 5 years ago

I have a morth that gives me certain "skin", or character. The character has a head and a mask. I want the player to press M to remove the mask. Now, I dont want to destroy it, I want to make the player take it off and take it back on, so I am willing to make it transparent. But I dont know how, my script failed. I want the button M to take it off and if I press it again it will bring back the mask. How can I fix the script? Please help.

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


--// Take Off The Mask:
mouse.KeyDown:connect(function(key)
    if key == "m" then
        script.Parent:FindFirstChild("Mask")
        if Mask.Transparency == 0 then
            Mask.Transparency = 1
        end
    end
end)


--// Take On The Mask:
mouse.KeyDown:connect(function(key)
    if key == "m" then
        script.Parent:FindFirstChild("Mask")
        if Mask.Transparency == 1 then
            Mask.Transparency = 0
        end
    end
end)

(The "Mask" is something thats inside the player`s character after I get the skin.)

0
KeyDown is deprecated Shawnyg 4330 — 5y
0
Still not working HeyItzDanniee 252 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Try this. Also you didn't set a variable for Mask, make sure you do that leading to the mask

--// Variables:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local input = game:GetService("UserInputService") -- The user input service
local maskOn = false -- Similar to debounce

--// Take OFF The Mask:
input.InputBegan:Connect(function(obj)
    if obj.KeyCode == Enum.KeyCode.M then
        if maskOn == true then
            Mask.Transparency = 1
            maskOn == false
        end
    end
end)


--// Put ON The Mask:
input.InputBegan:Connect(function(obj)
    if obj.KeyCode == Enum.KeyCode.M then
        if maskOn == false then
            Mask.Transparency = 0
            maskOn == true
        end
    end
end)
Ad

Answer this question