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

Character transparency script when player presses B?

Asked by 2 years ago
local playerz = game.Players.LocalPlayer
local character = playerz.Character
local uis = game:GetService("UserInputService")
local bodyparts = character:GetChildren()

uis.InputBegan:Connect(function(input, gameProcessedEvent)
    if uis.KeyboardEnabled then print("E") 
    if input.KeyCode == Enum.KeyCode.B then
            character = playerz.CharacterAdded:wait()
            for i, v in pairs(bodyparts) do
            if bodyparts:IsA("BasePart") then
            bodyparts.Transparency =1

             end
           end
        end
    end
end)



Trying to figure out why this code dosent work but im puzzled the code prints E since im on Studio using Keyboard but it wont go on to the next if statements of they straight up dont work

1 answer

Log in to vote
0
Answered by 2 years ago

It should work in a local script if you type the following.

local player = game.Players.LocalPLayer
local character = player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.E then
            for i,v in pairs (character:GetChildren()) do
                if v:IsA("BasePart") then
                    v.Transparency = 1
                end
            end
        end
    end
end

I believe your error was in checking if "bodyparts" (character:GetChildren()) was a basepart instead of v (each individual child).

0
Thanks for the help but still dosent work. Which is really odd to me since you fixed my table//loop better than me essentially might be I have to move the directory over to StarterPlayerScripts but not sure Bloxerventure 5 — 2y
0
IT WORKED THANK YOU just had to hold the key for a little longer Bloxerventure 5 — 2y
Ad

Answer this question