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

So I'm trying to make a admin panel GUI and I've tried making a face changer?

Asked by 3 years ago
Edited by JesseSong 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

But it keeps saying in output "Head is not a valid part of model". And It wont show to everyone. My code is below.

local player = game.Players.LocalPlayer
local character = player:FindFirstChild("Character")
local face = character.Head.face

script.Parent.MouseButton1Click:Connect(function()
    face.Texture = 663586235
end)

Also im trying to make it show for everyone.

Re-edited by JesseSong

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Character is not a child of player, but rather a property, so you can't use :FindFirstChild() here. We'll be removing that function because of this reason.

local player=game.Players.LocalPlayer
local character=player.Character
local face=character.Head.face

script.Parent.MouseButton1Click:Connect(function()
    face.Texture=663586235
end)

But wait, there's more! A character doesn't load in the instant you join the game, this can be rather tricky as you don't know exactly how long it'll take from the moment you joined to when your character will load. There is, however, an event called CharacterAdded and we can attach something called :Wait().

:Wait() is not the same as wait(). Let me explain:

  • :Wait() will pause the script until the event is fired

  • wait() will pause the script for whatever length of time you put in as an argument.

We'll add in the logical operator or followed by player.CharacterAdded:Wait().

local player=game.Players.LocalPlayer
local character=player.Character or player.CharacterAdded:Wait()
local face=character.Head.face

script.Parent.MouseButton1Click:Connect(function()
    face.Texture=663586235
end)

Unfortunately this was all a complete waste of time as you've said you wanted to have this visible to all players. LocalScripts handle the client and Scripts handle the server. We want to be changing the Texture property on the server so that this change is visible to everyone. We'll have to scratch everything and start anew. To start, we will want to create a RemoteEvent. Place the RemoteEvent in ReplicatedStorage and give it a name. In the LocalScript we will remove the following:

local player=game.Players.LocalPlayer local character=player.Character or player.CharacterAdded:Wait() local face=character.Head.face

as well as everything nested in the MouseButton1Click event:

face.Texture=663586235

You should end up with something looking like this:

script.Parent.MouseButton1Click:Connect(function()

end)

We're going to add the function :FireServer(). This is how the client communicates with the server. We will want to create a path to the RemoteEvent and use this function, which should look something like this:

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.NameOfYourRemoteEvent:FireServer()
end)

Next, we'll create a Script and put that in ServerScriptService. In the Script we'll add a listener for the aforementioned RemoteEvent using OnServerEvent. Which should look like this:

game.ReplicatedStorage.NameOfYourRemoteEvent.OnServerEvent:Connect(function(player)

end)

Reason we've put player as parameter is because the client will send LocalPlayer as the first parameter. Nested in the listener will be where we change the Texture property of face.

game.ReplicatedStorage.NameOfYourRemoteEvent.OnServerEvent:Connect(function(player)
    player.Character.Head.face.Texture="http://www.roblox.com/asset/?id=663586235"
end)

And now you're done and your script should be set!

0
Good answer but you wouldn't really need a removeevent in this case. Unless you'd want it to show for everyone in the server JesseSong 3916 — 3y
0
Below his code block he specifies: "Also im trying to make it show for everyone." efficacies 180 — 3y
Ad

Answer this question