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

how do I make a body transparency gui button ?

basically, when the player touches the part all his body gets invisible except the head so how do I make the same script but for a gui so that when the player clicks on the GUI button the same thing happens but with a gui button as a click function and not a touch function

function onTouch(part) 
local human = part.Parent:findFirstChild("Humanoid") 
if human ~= nil then 
part.Parent:findFirstChild("Head").Transparency = 0
part.Parent:findFirstChild("Torso").Transparency = 1
part.Parent:findFirstChild("Left Arm").Transparency = 1
part.Parent:findFirstChild("Right Arm").Transparency = 1
part.Parent:findFirstChild("Left Leg").Transparency = 1
part.Parent:findFirstChild("Right Leg").Transparency = 1
end 
end 
script.Parent.Touched:connect(onTouch) 

1 answer

✓ Accepted answer

I understand your question, but you must understand that you need to learn that. I will first try to teach it to you, then give the code. Let's hope you can learn and write your own code instead of copying the example I give to you =) If this helps, please upvote and accept as answer, thanks!

First of all, you need a GuiButton for that. It can be a TextButton, or an ImageButton, it's up to you. After you add it, you should know that GuiButtons have an event named MouseButton1Click. You can use that event. Here's usage of that event:

GuiButton.MouseButton1Click:Connect(function()
	print("Button1 Clicked")
end)

OR

function ClickMe()
	print("Button1 Clicked")
end

GuiButton.MouseButton1Click:Connect(ClickMe)

Now the code you need: For this code to work, you will need a Gu?Button and a LocalScript INSIDE that GuiButton.

function OnClick()
	local Player = game.Players.LocalPlayer
	local Character = Player.Character 
	if Character then
		Character:FindFirstChild("Head").Transparency = 0
		Character:FindFirstChild("Torso").Transparency = 1
		Character:FindFirstChild("Left Arm").Transparency = 1
		Character:FindFirstChild("Right Arm").Transparency = 1
		Character:FindFirstChild("Left Leg").Transparency = 1
		Character:FindFirstChild("Right Leg").Transparency = 1
	end 
end 

script.Parent.MouseButton1Click:Connect(OnClick)

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