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

More Hat Giver help please?

Asked by 8 years ago

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)
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? Legojoker 345 — 8y

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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").

Ad

Answer this question