Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Character transparency script when player presses B?

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

✓ Accepted answer

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).

2 comments

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

0

IT WORKED THANK YOU just had to hold the key for a little longer

This discussion is preserved as it was. New answers, comments, and votes are closed.