StarterCharacter only pertains to when the player joins the game / respawns, so using this method of changing the player is not useful for this scenario. In addition, it is preferred to use "Activated" so the function works on all devices (unless you are making a game for PC only)
Required for this set-up to work: Local Script under an Image / Text Button, Server Script in ServerScriptService, Remote Function in Replicated Storage (for this example, mine is named "RemoteFunction")
Local Script
local remote = game.ReplicatedStorage.RemoteFunction
script.Parent.Activated:Connect(function()
local reponse = remote:InvokeServer("Change1")
script.Parent.Parent.FrameSuccess.Visible = reponse
end)
This script allows the user to activate the gui button on the client, which will fire the server to change the player's character (this way other players can see the alteration, not just the current player) The reason I'm using a Remote Function is so that once the event moves to the server, it can, when finished, cause the "FrameSuccess" to become visible
Server Script
local remote = game.ReplicatedStorage.RemoteFunction
function remote.OnServerInvoke(player, msg)
if msg == "Change1" then
local char = workspace:FindFirstChild(player.Name)
if char ~= nil and char:FindFirstChild("Humanoid") ~= nil then
for i, v in pairs(char:GetDescendants()) do
if v.ClassName == "Accessory" then
v:Destroy()
end
end
for i, v in pairs(char:GetDescendants()) do
if v.Name == "face" then
v:Destroy()
end
end
if char:FindFirstChild("Shirt") ~= nil then
char.Shirt.ShirtTemplate = "rbxassetid://0"
end
if char:FindFirstChild("Pants") ~= nil then
char.Pants.PantsTemplate = "rbxassetid://0"
end
local color = char:FindFirstChild("Body Colors")
if color ~= nil then
color.HeadColor3 = Color3.new(0, 0, 0)
color.LeftArmColor3 = Color3.new(0, 0, 0)
color.RightArmColor3 = Color3.new(0, 0, 0)
color.LeftLegColor3 = Color3.new(0, 0, 0)
color.RightLegColor3 = Color3.new(0, 0, 0)
color.TorsoColor3 = Color3.new(0, 0, 0)
end
local accessory = Instance.new("Accessory")
local hair = Instance.new("Part")
local mesh = Instance.new("SpecialMesh")
local weld = Instance.new("Weld")
accessory.Name = "Hair"
accessory.Parent = char
hair.Name = "Handle"
hair.CanCollide = false
hair.Anchored = true
hair.Size = Vector3.new(1,1,1)
hair.Parent = accessory
weld.Parent = hair
weld.Part0 = hair
weld.Part1 = char.Head
weld.C0 = CFrame.new(0, 0, 0)
hair.Anchored = false
mesh.MeshId = "rbxassetid://0"
mesh.TextureId = "rbxassetid://0"
mesh.Scale = Vector3.new(1, 1, 1)
mesh.Parent = hair
wait()
return true
end
end
end
Throughout this script, I've written what each piece of the function does and how you can alter it for your purposes. The above script, based on how your initially given script was written, will only change the player's character once.
3 comments
'not working' and 'it wont work' are not ways to tell if something is not working. We don't know what are the output errors (if there is/are), we don't know if StarterCharacter is a character model, we don't know if this script is local or not...
that isnt FE compatable
its local i tired both ways no errors too...