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

Problems with click detecting. Help?

This script is inside a part that is supposed to give you a special hammer, but it wont print the message. (I just use the message to see how far the script gets when fired)

local ClickDetector = script.Parent:WaitForChild("ClickDetector")
local p = game.Players.LocalPlayer
local backpack = p:WaitForChild("Backpack")
local Tool = game.ReplicatedStorage:FindFirstChild("Carbonite Hammer")

 
script.Parent.MouseClick:connect(function()
	print("Working") --This never gets printed
	--local Backpack = player:WaitForChild("Backpack")
	--local Tool = Storage:FindFirstChild("Carbonite Hammer")
	local nTool = Tool:clone()
	nTool.parent = backpack
	--script:Destroy()
end)

What am i doing wrong?

1 answer

✓ Accepted answer

its because your doing MouseClick on the Part, not the ClickDetector, because BasePart doesnt hold a MouseClick event, so it doesnt work. So just do the MouseClick event on the clickdetector, since thats what its used for.

ClickDetector.MouseClick:Connect(function() -- :connect is decaperated use :Connect
end)

Also, you cant access LocalPlayer through server scripts if ur using one, because if u play online it wont work, since only local scripts can access it.

1 comment

0

Oki, thanks!

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