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

Modifying this into a click hat giver?

Asked by 9 years ago

Hi, I have been trying to come up with a way to create this into a click hat giver rather than a ontouch hat giver. I have added a click detector, what would I need to do to convert this into a click giver?

debounce = true

function onTouched(hit)
    if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
        debounce = false
        h = Instance.new("Hat")
        p = Instance.new("Part")
        h.Name = "Hat"   
        p.Parent = h
        p.Position = hit.Parent:findFirstChild("Head").Position
        p.Name = "Handle" 
        p.formFactor = 0
        p.Size = Vector3.new(-0,-0,-1) 
        p.BottomSurface = 0 
        p.TopSurface = 0 
        p.Locked = true 
        script.Parent.Mesh:clone().Parent = p
        h.Parent = hit.Parent
        h.AttachmentPos = Vector3.new(0,0.4,-0.025) 
        wait(5)     debounce = true
    end
end

script.Parent.Touched:connect(onTouched)
0
No, this doesn't happen to work, thank you for your answer though. GameBuilderModerator 0 — 9y

1 answer

Log in to vote
0
Answered by
Vrakos 109
9 years ago

I am have not tested this, as I am not on a computer with ROBLOX Studio downloaded. If this works, then please accept this answer, if not, please leave a reply with the output.

debounce = true

if not script.Parent:findFirstChild("ClickDetector") then
    local cd = Instance.new("ClickDetector")
    cd.Parent = script.Parent
end

script.Parent.ClickDetector.MouseClick:connect(function(player)
local character = player.Character
    if (character:findFirstChild("Humanoid") ~= nil and debounce == true) then
        debounce = false
        h = Instance.new("Hat")
        p = Instance.new("Part")
        h.Name = "Hat"   
        p.Parent = h
        p.Position = character:findFirstChild("Head").Position
        p.Name = "Handle" 
        p.formFactor = 0
        p.Size = Vector3.new(-0,-0,-1) 
        p.BottomSurface = 0 
        p.TopSurface = 0 
        p.Locked = true 
        script.Parent.Mesh:clone().Parent = p
        h.Parent = hit.Parent
        h.AttachmentPos = Vector3.new(0,0.4,-0.025) 
        wait(5)     debounce = true
    end
end)

0
I think you could even just do script.Parent.MouseButton1Down:connect(function() and it would add the click detector to the part, not sure though dragonkeeper467 453 — 9y
0
@dragonkeeper467 The 'MouseButton1Down' event can only be used for GUIs (TextButtons and ImageButtons only). TheeDeathCaster 2368 — 9y
Ad

Answer this question