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

Character Customization UI? (Pertaining to Hair)

Asked by
Aezion 2
3 years ago

So I'm trying to make a character customization UI for my game. Common enough nowadays, it seems. I so far have got everything working on it. Except hair. I keep watching youtube tutorials and frankly none of them out there seem to work for the style of UI that I'm attempting.

I have it to where you see a dummy in a viewport frame and the idea is the different options affect the dummy so you can have a general idea of how your character will look once you load into the main game server(s). That works well.

Well instead of selecting one from a box that contains all options, like most videos I find, such as one tutorial from TheVenomousOwl, I want it to where you click left or right arrows to scrolls through the options, where it loads Hair0 on the dummy as the base option, clicking right removes Hair0, clones Hair1 from ReplicatedStorage, and places the cloned Hair1 onto the dummy, clicking right again removes Hair1 and clones Hair2 onto the dummy, so on and so forth, using a StringValue within the dummy to keep track for the script.

Well for whatever reason I cannot for the life of me figure out how to get this to work properly. So far for testing I just have Hair0 and Hair1 and click right from Hair0 should bring you from Hair0 to Hair1 and clicking right from Hair1 should bring you back to Hair0. I'll put my code below, because I'm fairly certain I'm just an idiot and don't know what I'm actually doing (because I don't) but with my current code it:

Removes Hair0 and clones Hair1 into the dummy, so that's functioning right

But what it doesn't do:

Won't remove Hair1 and clone Hair0 into the dummy (yikes) Doesn't change stringvalue from Hair0 to Hair1 (yikes) Doesn't place Hair1 onto the dummy's head, rendering it invisible to the player (and essentially useless)

local RightButton = script.Parent
local Hair0 = game.ReplicatedStorage.Hair0:Clone()
local Hair1 = game.ReplicatedStorage.Hair1:Clone()

local function onButtonActivated()
    if game.Workspace.Dummy.Hair.Value == "Hair0" then
        game.Workspace.Dummy.Hair0:Remove()
        Hair1.Parent = game.Workspace.Dummy
        Hair1.Position = game.Workspace.Dummy.Head.Position
        local Weld = Instance.new("Weld")
        Weld.Parent = Hair1
        Weld.Part0,Weld.Part1 = game.Workspace.Dummy.Head, Hair1
        Weld.C0 = CFrame.new(0,0.6,0)
        Weld.C1 = game.Workspace.Dummy.Head.HairAttachment.CFrame
        game.Workspace.Dummy.Hair.Value = "Hair1"
    elseif game.Workspace.Dummy.Hair.Value == "Hair1" then
        game.Workspace.Dummy.Hair1:Remove()
        Hair0.Parent = game.Workspace.Dummy
        Hair0.Position = game.Workspace.Dummy.Head.Position
        local Weld = Instance.new("Weld")
        Weld.Parent = Hair0
        Weld.Part0,Weld.Part1 = game.Workspace.Dummy.Head, Hair0
        Weld.C0 = CFrame.new(0,0.6,0)
        Weld.C1 = game.Workspace.Dummy.Head.HairAttachment.CFrame
        game.Workspace.Dummy.Hair.Value = "Hair0"
    end
end

RightButton.Activated:Connect(onButtonActivated)

Any and all help with fixing those three glaring problems would be very appreciated, as well as any resources or explanations for furthering my own learning so that when I try to add other hair in beyond just these test two so that Hair2 doesn't have the problem Hair1 is having where it's nowhere to be seen. Because for some reason I'm having a great deal of difficulty with hair in my game. Even just cutting and pasting into the dummy, half the time the hair renders on its head and the other half the time it's like 3 studs above his head or some other odd place and I really have no clue what's going on because that's with me making no edits to the hair just copying and pasting so I'm really frustrated and confused with the hair system right now, so if anyone can explain why it sometimes is on his head and sometimes isn't, without any changes made, I would be really really appreciative.

Thanks for any and all information available! If possible I would prefer an explanation as to what's wrong as well as how to remedy it rather than just a "fixed code" to paste in because ultimately I'd love to understand what's actually going on in order to become better at scripting for my game. Thanks again!

0
Can I bump this? Like even if someone could just point me in the right direction :v Aezion 2 — 3y

Answer this question