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

I need help with a hat giver. [?]

Asked by 8 years ago

I'm trying to make a giver that puts a part with a decal on your head. help?

debounce = true

function OnClicked()
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"
    h.Name = "Hat"
    p.Parent = h
    p.Transparency = 1
    p.Position = script.Parent.Parent.Parent.Parent:findFirstChild("Head").Position
    p.Name = "Handle" 
    p.formFactor = 0
    p.Size = Vector3.new(0.2,1,1) 
    p.BottomSurface = 0 
    p.TopSurface = 0 
    p.Locked = true 
    h.Parent = script.Parent.Parent.Parent.Parent
    h.AttachmentPos = Vector3.new(0,-0.75,-0.5)
    wait(5)
    debounce = true
end
end

script.Parent.MouseButton1Click:connect(OnClicked)

Nothing shows up in the output box, but the script doesn't do anything

0
I fixed the (OnTouched), it still does nothing connor12260311 383 — 8y
0
Is script.Parent a GUI? Goulstem 8144 — 8y
0
No, it is an image button connor12260311 383 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

script.Parent.MouseButton1Click:connect(OnClicked), not onTouched. Only problem I see.

Ad
Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

I added a click detector in your part, but if you already have one delete the line

local Click = Instance.new('ClickDetector', Main)

Second, I cleaned up your code a bit plus, MouseClick gives you a Player not the Character of the Player. So you got to find the Character that click the button instead to deliver the hat.

local function OnClicked(Player)
    if Player.Character:FindFirstChild("Humanoid") and debounce then
        debounce = not debounce
        local h = Instance.new("Hat", Player.Character)
        local p = Instance.new("Part", h)
        local d = Instance.new("Decal", p)

Thirdly, you need to use MouseClick for the click detector, not MouseButton1Click

Click.MouseClick:connect(OnClicked)

Here is the completed and tested code:

local debounce = true
local Main = script.Parent
local Click = Instance.new('ClickDetector', Main)

local function OnClicked(Player)
    if Player.Character:FindFirstChild("Humanoid") and debounce then
        debounce = not debounce
        local h = Instance.new("Hat", Player.Character)
        local p = Instance.new("Part", h)
        local d = Instance.new("Decal", p)
        d.Texture = "http://www.roblox.com/asset/?id=306287357"
        h.Name = "Hat"
        p.Transparency = 1
        p.Position = Player.Character:findFirstChild("Head").Position
        p.Name = "Handle" 
        p.formFactor = 0
        p.Size = Vector3.new(0.2,1,1) 
        p.BottomSurface = 0 
        p.TopSurface = 0 
        p.Locked = true
        h.AttachmentPos = Vector3.new(0,-0.75,-0.5)
        wait(5)
        debounce = true
    end
end

Click.MouseClick:connect(OnClicked)

If you want the part to stay on the head, you need to weld it. Right now it just creates a part on top of the player's head and falls off. But your current code is fixed.

Hope I helped

0
Im sorry. You worked very hard, but it was supposed to work when you touch an image button connor12260311 383 — 8y

Answer this question