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

Add Accessories through GUI Code, not working, fix?

Hello all! I am creating a GUI that when clicked gives your character an accessory in ServerStorage. I don't understand as to why this doesn't work, as it says it should run!

local playerModel = game.Players.LocalPlayer

local Character = workspace:FindFirstChild(playerModel.Name)

script.Parent.MouseButton1Click:Connect(function()

if Character:FindFirstChild("Humanoid") then

game.ServerStorage.BlackHair:Clone().Parent = Character

script.Parent.Parent:Destroy()

end

end)

1 answer

✓ Accepted answer

You need to set the position of the hat. You cannot just assign its parent to Character without giving it any info on where its going to go.

local playerModel = game.Players.LocalPlayer
local Character = workspace:FindFirstChild(playerModel.Name)

  

script.Parent.MouseButton1Click:Connect(function()
    if Character:FindFirstChild("Humanoid") then
	    local h = Instance.new("Hat")
	    local p = Instance.new("Part")
	    h.Name = "Hat"
	    p.Parent = h
	    p.Position = hit.Parent:findFirstChild("Head").Position
	    p.Name = "Handle"
	    p.formFactor = 0
	    p.Size = Vector3.new(1, 0.4, 1)
	    p.BottomSurface = 0
	    p.TopSurface = 0
	    p.Locked = true
	    game.ServerStorage.BlackHair:Clone().Parent = Character
	    h.Parent = Character
	    h.AttachmentForward = Vector3.new (-0, -0, -1)
	    h.AttachmentPos = Vector3.new(0, 0.4, 0)
	    h.AttachmentRight = Vector3.new (1, 0, 0)
	    h.AttachmentUp = Vector3.new (0, 1, 0)
wait(5)

end

end)

My code may not all be correct but I hope you understand that you'll need to give it coordinates.

3 comments

0

Would "Hat" Be considered Accessory now? Or would "hat" Still function?

0

Accessory

0

I get an error that says "attempt to index field "parent" (a nil value)" Line 12

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