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.
1 | local player = game.Players.LocalPlayer |
2 | local character = player.Character |
3 | local face = character.Head.face |
5 | script.Parent.MouseButton 1 Click:Connect( function () |
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:
We'll add in the logical operator or
followed by player.CharacterAdded:Wait()
.
1 | local player = game.Players.LocalPlayer |
2 | local character = player.Character or player.CharacterAdded:Wait() |
3 | local face = character.Head.face |
5 | script.Parent.MouseButton 1 Click:Connect( function () |
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:
1 | script.Parent.MouseButton 1 Click:Connect( function () |
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:
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | game.ReplicatedStorage.NameOfYourRemoteEvent:FireServer() |
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:
1 | game.ReplicatedStorage.NameOfYourRemoteEvent.OnServerEvent:Connect( function (player) |
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.
1 | game.ReplicatedStorage.NameOfYourRemoteEvent.OnServerEvent:Connect( function (player) |
And now you're done and your script should be set!