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
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?