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

I need help with a hat giver. [?]

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

3 comments

0

I fixed the (OnTouched), it still does nothing

0

Is script.Parent a GUI?

0

No, it is an image button

2 answers

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

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

1 comment

0

Im sorry. You worked very hard, but it was supposed to work when you touch an image button

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