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

Problems with click detecting. Help?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Oki, thanks! GlennJoakim 35 — 5y
Ad

Answer this question