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

Why won't this script that is placed in a GUI remove the players face and replace it when clicked?

player = game.Players.LocalPlayer
h = player.Character
script.Parent.MouseButton1Down:connect(function()
h.face:Destroy()
wait(0.01)
newface = Instance.new("Decal",h)
newface.Head = "Front" 
newface.Name = "face"
newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end

When I select on the gui the players face is not removed.

4 comments

0

Is this a Script or a LocalScript?

0

A local script.

0

Hello?

0

Why ask if you won't do anything.

2 answers

✓ Accepted answer

The problem is h. Variable h is the character. Not the head that the face is it. You also need a ) after the end. This is because the function is in the connect. This is a shorter way to write event scripts but you need the ). So basicly you just need to close the parentheses. Here this is better:

player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
h.face:Destroy()
--No wait needed.
local newface = Instance.new("Decal",h)
newface.Head = "Front" 
newface.Name = "face"
newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end) --You need the ")" because of line 3.

Hat:

player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
	h.face:Destroy()
	for _,v in pairs(player.Character:GetChildren()) do
		if v.ClassName == "Hat" then
			v:Destroy()
			game.ServerStorage.Hat:clone().Parent = player.Character --Put the hat in ServerStorage and name it "Hat".
		end
	end
	local newface = Instance.new("Decal",h)
	newface.Name = "face"
	newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end)

EDIT:

For multiple hats and this is both of the scripts combined

player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
	if not h.face.Texture == "http://www.roblox.com/asset/?id=138224650" then
	h.face:Destroy()
	for _,v in pairs(player.Character:GetChildren()) do
		if v.ClassName == "Hat" then
			v:Destroy()
			for _,i in pairs(game.ServerStorage:GetChildren()) do
			i:clone().Parent = player.Character
			player.Character:MakeJoints()
			end
		end
	end
	local newface = Instance.new("Decal",h)
	newface.Name = "face"
	newface.Texture = "http://www.roblox.com/asset/?id=138224650"
	end
end)

2 comments

0

Excuse me. I need more help. I want a player to get a certain Hat when they click on the Gui. I was afraid to ask because I don't know how to script that. How would I do that?

0

I am having an error the face is removed but the new one is not shown.

Hats:

p = game.Players.LocalPlayer
char = p.Character
Storage = game:GetService("ServerStorage") --Using :GetService() because the script can cause an error if used in multiplayer(uploaded to roblox) when not calling the service

script.Parent.MouseButton1Down:connect(function()
	local cont = char:GetChildren()
	for i,v in pairs(cont) do -- Removing all other hats
		if v:IsA("Hat") then
			v:Destroy()
		end
	end
	local hat = Storage.HATNAME:clone() --Change HATNAME to the name of the hat and put the hat in ServerStorage
	hat.Parent = char
	hat.Name = "Hat"
	--If the hat is not anchored in ServerStorage it should appear on your head.
end)

1 comment

0

Does :IsA("Hat") work? This doesn't do multiple hats, and the hats don't stick. Use :MakeJoints() on the character to make it stick.

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