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

Hat that is a part with a decal giver trouble! Help?

Asked by 8 years ago

This is a script that is supposed to give you a part on your head and weld it on to it

function GiveHat()

if HatOn == False then 

local I = Instance.new("Part")

local D = Instance.new("Decal")

local T = script.Parent.Parent.Parent.Parent:FindFirstChild("Head")

D.Parent = I

D.Texture = "http://www.roblox.com/asset/?id=149397688" 

I.Parent = T

I.CanCollide = false

I.Size = Vector3.new(0.2,1,0.2)

print("Part Created")

--Weld I and T

I.Position = T.Position + Vector3.new(0,1,0)

script.Parent.HatOn = true

else

local T = script.Parent.Parent.Parent.Parent:FindFirstChild("Head")

HatOn = false

T.I:Destroy()

end

end

script.Parent.MouseButton1Down:connect(GiveHat)

This is the exact code I'm having trouble with. Everytime I run it, it always says "attempt to index local "T"(a nil value)" and yes, script.Parent.Parent.Parent.Parent is the player.

also I don't know how to weld the 2 parts together

1 answer

Log in to vote
0
Answered by 8 years ago

First, make sure that you are properly indexing that Head. Check if script.Parent.Parent.Parent.Parent really contains the Head (You are probably searching for a character model).

Try print(script.Parent.Parent.Parent.Parent) and see if it prints the player's name.

Second, you want to make the hat stay on the head? Well, you should use welds.

http://wiki.roblox.com/index.php/Weld

If you need help with welding, make sure to leave a comment.

Hope this helped.

0
script.Parent.Parent.Parent.Parent is the player name, i checked but it still doesnt work connor12260311 383 — 8y
Ad

Answer this question