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

Is there any way i can detect when a player uses a tool? My way is not working.

Asked by 4 years ago
Edited 4 years ago

In my code, at the if statement on line 21, it SHOULD be detecting when the mouse is clicked. But in my console, it is not printing "Player has thrown a knife." Even when i told it to when the tool is used. Everything EXCEPT this if statement works. But the weird thing is, i am not getting any errors.

ReplicatedStorage.GiveKnife.OnServerEvent:Connect(function(player)
    local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid:UnequipTools()
        print("Knife deselected.")
    end
    if player.Backpack:FindFirstChild("Knife") then
        player.Backpack.Knife:Destroy()
        print("Knife destroyed")
    end

    myKnife = game.ServerStorage.Knife:Clone()
    myKnife.Parent = player.Backpack
    myKnife.Name = "Knife"
    print("Knife created")

    myKnife.Equipped:Connect(function(mouse)
        mouse.MouseButton1Click:Connect(function(player)
            print(player.."has thrown a knife.")
        end)
    end)
end)
0
Maybe try myKnife.Activated? charizardstar87 16 — 4y
0
MouseButton1Click is an RBXScriptSignal of GUIButton. You're looking for Button1Down. Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

make a localscript in the tool and create ur code there

local tool = script.Parent --  your tool

function onActivation()
    local plr = game.Players.LocalPlayer.DisplayName
    print(plr.." has thrown a knife.")
end

tool.Activated:Connect(onActivation)
0
ofc this is locally so anything server related will have to be done with remote events Pitched_mobile 191 — 4y
0
Thanks Bigmancozmo 7 — 4y
Ad

Answer this question