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

HELP Character Picker NOT working!?

Asked by 5 years ago

so im making a game and u get to choose ur character by cliking it but! it wont work! i want it like this: I have a gui and the frame and the text button if u click it it makes u that character. whats the matter?

script.Parent.MouseButton1Click:Connect(function()
    local char = game.ReplicatedStorage.StarterCharacter:Clone() -- This creates an actual clone
    char.Parent = game.StarterPlayer
    script.Parent.Parent.FrameSuccess.Visible = true
end)
0
'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... Miniller 562 — 5y
0
that isnt FE compatable theking48989987 2147 — 5y
0
its local i tired both ways no errors too... legendarycoos11 1 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
            -- Remove Prior Accessories
            for i, v in pairs(char:GetDescendants()) do
                if v.ClassName == "Accessory" then
                    v:Destroy()
                end
            end
            -- Remove Face (Not Required, Only if you have another to force the user to wear)
            for i, v in pairs(char:GetDescendants()) do
                if v.Name == "face" then
                    v:Destroy()
                end
            end
            -- Changes Shirt, if applicable
            if char:FindFirstChild("Shirt") ~= nil then
                char.Shirt.ShirtTemplate = "rbxassetid://0" -- Asset Id of Shirt
            end
            -- Changes Pants, if applicable
            if char:FindFirstChild("Pants") ~= nil then
                char.Pants.PantsTemplate = "rbxassetid://0" -- Asset Id of Pants
            end
            -- Changes Body Colors, if applicable, not required
            local color = char:FindFirstChild("Body Colors") -- Each Color Ranges from 0 to 255
            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
            -- Adds New Hair or Other Accessory
            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) -- Test in Studio to Determine correct offset
            hair.Anchored = false

            mesh.MeshId = "rbxassetid://0" -- Mesh Id
            mesh.TextureId = "rbxassetid://0" -- Texture Id
            mesh.Scale = Vector3.new(1, 1, 1)
            mesh.Parent = hair
            wait()
            return true -- This is the second part of the remote function, firing to the client
        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.

Ad

Answer this question