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

More Hat Giver help please?

I made a hat script that works if you step on a block, it gives you a hat

debounce = true

function onTouched(hit)
	if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
	debounce = false
	local h = Instance.new("Hat")
	local p = Instance.new("Part")
	local d = Instance.new("Decal")
	d.Parent = p
	d.Texture = "http://www.roblox.com/asset/?id=306287357"
	local d1 = d:Clone()
	d1.Parent = p
	d1.Face = ("Back")
	h.Name = "Galalaga"
	p.Name = "Galalaga"
	d.Name = "Galalaga"
	p.Parent = h
	p.Transparency = 1
	p.Position = hit.Parent:findFirstChild("Head").Position
	p.Name = "Handle"
	p.FormFactor = ("Custom") 
	p.Size = Vector3.new(1,1,0.2) 
	p.BottomSurface = 0 
	p.TopSurface = 0 
	p.Locked = true 
	h.Parent = hit.Parent
	h.AttachmentPos = Vector3.new(0,-0.75,0)
	wait(5)
	debounce = true
end
end
script.Parent.Touched:connect(onTouched)

the script works perfectly until I try to make it work with an image button

debounce = true

function onTouched()
		if (script.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") ~= nil and debounce 	== true) 	then
	debounce = false
	local h = Instance.new("Hat")
	local p = Instance.new("Part")
	local d = Instance.new("Decal")
	d.Parent = p
	d.Texture = "http://www.roblox.com/asset/?id=306287357"
	local d1 = d:Clone()
	d1.Parent = p
	d1.Face = ("Back")
	h.Name = "Galalaga"
	p.Name = "Galalaga"
	d.Name = "Galalaga"
	p.Parent = h
	p.Transparency = 1
	p.Position = script.Parent.Parent.Parent.Parent:findFirstChild("Head").Position
	p.Name = "Handle"
	p.FormFactor = ("Custom") 
	p.Size = Vector3.new(1,1,0.2) 
	p.BottomSurface = 0 
	p.TopSurface = 0 
	p.Locked = true 
	h.Parent = script.Parent.Parent.Parent.Parent
	h.AttachmentPos = Vector3.new(0,-0.75,0)
	wait(5)
	debounce = true
end
end
script.Parent.MouseButton1Down:connect(onTouched)

1 comment

0

It would help if we could see your Explorer window and how you have your parents and descendants set up for the image button. Are there any errors that appear? What type of script are you using, server or local?

1 answer

It looks like script.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") is supposed to be accessing the Humanoid through the Player. The Humanoid is not in the Player, though, the humanoid is in the Character. If script.Parent.Parent.Parent.Parent is indeed the player, then the Humanoid is script.Parent.Parent.Parent.Parent.Character:FindFirstChild("Humanoid").

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