Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's wrong with my script which giving T-shirt?

Hi, I have script which giving T-shirt (decal), but something is wrong here in 4 line. Exactly Players.DodusiakPL.PlayerGui.UniformGui.Frame.US.Ubranie.Script:4: attempt to index nil with 'Character' I don't have idea what's wrong, any ideas? (script written in LocalScript)

This is this script

local Decal = script.Parent:FindFirstChildOfClass("Decal")

script.Parent.MouseButton1Click:connect(function(Player)
    local Character = Player.Character
    for i,v in pairs(Character:GetDescendants()) do
        if v:IsA("ShirtGraphic") then
            v:Destroy()
        end
    end
    local ShirtGraphic = Instance.new("ShirtGraphic")
    ShirtGraphic.Graphic = Decal.Texture
    ShirtGraphic.Parent = Character
end)

1 answer

Your character does not exist or the code is executed before character is loaded. For that use:

if not player.Character then
player.CharacterAppearanceLoaded:Wait() -- waits until it loads
end
local character = player.Character

-- or this

player.CharacterAppearanceLoaded:Connect(function(character) -- fires function when loaded
local character = character
end) -- this one might be better as when he resets it executes too
-- the problem with this function is that character somehow loads faster than it is executed so for first time it won't work, but it is possible to fix if combined with the first thing

EDIT: Sorry, sorry my bad i did not read the problem carefully, player is nil, to access player in local script you use this:

local player = game.Players.LocalPlayer

3 comments

0

Both not working

0

Then you are probably doing something not so right i guess, you should try to check roblox devforum as there is definitely answer for that,

0

I edited it sorry, i was wrong

This discussion is preserved as it was. New answers, comments, and votes are closed.