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

How do I fix my HopperBin so it activates onButton1Down?

bin = script.Parent
print("Loaded")
function onButton1Down(mouse)
	print("CLICK1")

	local model = bin.house:clone() 

	model.Parent = game.Workspace
	model:MakeJoints()
	model:MoveTo(mouse.hit.p)
	
	wait(0.2)
	script.Parent:Remove()
end

function onSelected(mouse)
	print("MARK1")
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

script.Parent.Selected:connect(onSelected)

It prints up to MARK1 but never prints CLICK1 so I assume the problem is inside the line trying to connect the function onButton1Down but have no idea how to fix it. I already checked the wiki and didn't notice anything.

3 comments

0

It isn't a localscript is it?

0

No it isn't

0

Change it to a localscript and you'll be all set to go.

1 answer

✓ Accepted answer

First of all, tools should contain a local script, not a script. Secondly, don't use HopperBins! These a deprecated and Tools function perfectly! Before you say anything, to make a tool work the same way as a HopperBin seems to work would select your tool instance and deselect Requires Handle in the properties. Now it's pretty much like a HopperBin.

So, how can we do a similar script that you've provided, but with a tool instead? Just look bellow and view the commenting for explanation. If this helps, toss a +1 and if you have question, comment away.

local Tool = script.Parent
local Plr = game.Players.LocalPlayer
local Equipped = false
local Used = false

Tool.Equipped:connect(function(mouse)-- Gives the Mouse
	Equipped = true
	mouse.Button1Down:connect(function() -- Fire on Button1Down
		if Equipped and not Used then -- Make sure they can't click a lot and create multiple!
			Used = true
			local model = script.Parent.house:clone()
			model.Parent = game.Workspace
			model:MakeJoints()
			model:MoveTo(mouse.hit.p)
			wait(0.2)
			script.Parent:Remove()
		end
	end)
	
	Tool.Unequipped:connect(function()
		Equipped = false -- So the mouse wouldn't fire if you unequip then click
	end)
end)

1 comment

0

Thank you!

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