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

Add Accessories through GUI Code, not working, fix?

Asked by
BryanFehr 133
5 years ago

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

Log in to vote
2
Answered by 5 years ago

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.

0
Would "Hat" Be considered Accessory now? Or would "hat" Still function? BryanFehr 133 — 5y
0
Accessory cooldrewbie 94 — 5y
0
I get an error that says "attempt to index field "parent" (a nil value)" Line 12 BryanFehr 133 — 5y
Ad

Answer this question