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

My Custom character script won't work in-game or on solo mode what's wrong?

Asked by 7 years ago

Basically, this is my first time creating a custom character creator. I've been trying for a while to try and figure out why this error keeps coming up

Players.Player1.PlayerGui.CharacterCreatorFigure:27: attempt to index field 'Value' (a nil value)

the script this is coming from is as follows:

repeat wait() until game.Workspace.CurrentCamera
local Camera = game.Workspace.CurrentCamera

local Character = game:GetService("ReplicatedStorage"):WaitForChild("CreatorChar"):Clone()
local Base = game:GetService("ReplicatedStorage"):WaitForChild("CharBase"):Clone()

local player = game.Players.LocalPlayer

local Hat = player:WaitForChild("Hat")
local Shirt = player:WaitForChild("Shirt")
local Pants = player:WaitForChild("Pants")

Base.Parent = Camera
Character.Parent = Camera

------------Functions--------------

function Update()
    for i,v in pairs(Character:GetChildren()) do
        if v:IsA("Hat") or v:IsA("Shirt") or v:IsA("Pants") then
            v:Destroy()
        end
    end

    Hat.Value:Clone().Parent = Character --.Value
    wait()
    Shirt.Value:Clone().Parent = Character
    wait()
    Pants.Value:Clone().Parent = Character
end


Hat.Changed:connect(function()
    Update()
end)

Shirt.Changed:connect(function()
    Update()
end)

Pants.Changed:connect(function()
    Update()
end)

The actual creator spans over multiple scripts, I need some help desperetely or an alternative

1 answer

Log in to vote
1
Answered by 7 years ago

Everytime you run the update function, you're destroying your objects pointed to on lines 9-11. So naturally you'll get a nil error - im surprised you don't get it on line 25.

I see you're using .Value - so do you actually have "Object" objects named Hat, Pants, and Shirt? If so, I'd rename these and not point them to what's on the character, but what you have in replicated storage. One thing I did was have folders in replicated storage with Hats, Shirts, and Pants, and then had an index with the current item of each category being looked at, so you could easily reference each one with a line of code like this:

local rs = game.ReplicatedStorage
local shirtindex = rs.Shirts.shirtindex.Value -- Int value object
local selected_shirt = rs.Shirts:getChildren()[shirtindex] 

Anyway, just an idea. This could probably simplify a lot of your code, following a setup like this.

Ad

Answer this question