Last month I asked for help with a Face Changing GUI, since I kept getting this error: "attempt to index nil with 'Character' error". Someone was kind enough to explain what the issue was and even provided a working version of my code, which is the following:
local char = game.Players.LocalPlayer.Character local f = script.Parent.MakeUps:GetChildren() local head = char:WaitForChild("Head") for _,v in pairs(f) do if v:IsA("ImageButton") then v.MouseButton1Click:Connect(function() head.face.Texture = v.Image end) end end
While this code does exactly what I wanted it to do (changing my avatar's face with the one selected from the GUI), the result doesn't reproduce on other people's client. Instead, it just looks like you have no face. I figured out that I need to use Remote Events to "bypass" FE and allow other players to see the change too, which is what I did, but sadly it doesn't seem to work, probably due to my lack of experience with Remote Events.
This is the result of my attempt at using Remove Events:
In StarterCharacterScripts, LocalScipt
local RS = game:GetService("ReplicatedStorage") local GUISer = game:GetService("StarterGui") local frame = GUISer.MugChanger.MK.Frame local char = game.Players.LocalPlayer.Character local head = char:WaitForChild("Head") local RemoteEvent = RS:WaitForChild("MakeUpChange") local MakeUps,MakeUps = frame.NarrowHead.MakeUps:GetChildren(), frame.WomanHead.MakeUps:GetChildren() for _,v in pairs(MakeUps) do if v:IsA("ImageButton") then v.MouseButton1Click:Connect(function() RemoteEvent:FireServer(head) end) end end
In ServerScriptService, Script
local RS = game:GetService("ReplicatedStorage") local RemoteEvent = RS:WaitForChild("MakeUpChange") RemoteEvent.OnServerEvent:Connect(function(player,v,head) head.face.Texture = v.Image end)
I assume it's something related to the arguments used in the functions, which is the part I least understand at the moment, but I'm not sure. Is someone able to help me fixing the code?
EDIT: no errors reported in the console.
Tell me if this doesnt work, i noticed some errors, maybe i can fix them
local plr = game.Players.LocalPlayer local RS = game:GetService("ReplicatedStorage") local PlayerGui = plr:WaitForChild("PlayerGui") --Changed because the GuiService replicates a folder into the player named "PlayerGui" local frame = PlayerGui.MugChanger.MK.Frame local char = plr.Character or plr.CharacterAdded:Wait() --Waits until the event fires to prevent errors local head = char:WaitForChild("Head") local RemoteEvent = RS:WaitForChild("MakeUpChange") local MakeUps,MakeUps = frame.NarrowHead.MakeUps:GetChildren(), frame.WomanHead.MakeUps:GetChildren() for _,v in pairs(MakeUps) do if v:IsA("ImageButton") then v.MouseButton1Click:Connect(function() RemoteEvent:FireServer(v, head) end) end end
Server script:
local RS = game:GetService("ReplicatedStorage") local RemoteEvent = RS:WaitForChild("MakeUpChange") RemoteEvent.OnServerEvent:Connect(function(player,v,head) head.face.Texture = v.Image end)
Tell me if something goes wrong,so i can help