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

Modifying this into a click hat giver?

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)

1 comment

0

No, this doesn't happen to work, thank you for your answer though.

1 answer

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)

2 comments

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

0

@dragonkeeper467 The 'MouseButton1Down' event can only be used for GUIs (TextButtons and ImageButtons only).

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