I am trying to figure out how to make it so that, it checks if the player clicked their mouse and the tool they are holding is touching something. I know the functions, and event stuff. I just don’t know how to put it together.
Basically you can either do a mousebutton1 down or user input began on mouse button 1 then run a check to find a tool in the character
local tool = Character:FindFirstChildWhichIsA(“Tool”) --i think thats what it is
then run a if statement
if tool then
– then you can fire the remote even you want
end
Roblox has created a specific event for tools on a “clicked” event, like this:
tool.Activated:Connect(function()
The activated event will register the click when a player is holding a tool
Then you can use the Handle part of a tool and used the Touched event to check if it is colliding with a Part or something
It’s not working.
glove.Activated:Connect(function()
if canslap == true then
canslap = false
hand.Touched:Connect(function(hit)
local targetedplayer = hit.Parent
local humanoid = targetedplayer:FindFirstChild("Humanoid")
local locatedhead = targetedplayer:FindFirstChild("Head")
if humanoid then
playerslapped:FireServer(targetedplayer, humanoid, locatedhead)
end
end)
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.SlapAnim)
animation:Play()
wait(2)
canslap = true
end
end)
Is your tool’s property “Enabled” set to check?
I would also do
if #hand:GetTouchingParts() > 0 then
end
this checks if its currently touching something or not
Why not use .Touched event though?
I didn’t understand you much, if the tool is only usable when its touching something use the code I sent, if not use ClientCast V2 for hitboxes (If you want a more reliable one) or use .Touched
And use Tool.Activated:Connect(function()
I tried this, and it ended up not working.
if #hand:GetTouchingParts() > 0 then
local hit = hand:GetTouchingParts()
local targetedplayer = hit.Parent
local humanoid = targetedplayer:FindFirstChild("Humanoid")
local locatedhead = targetedplayer:FindFirstChild("Head")
if humanoid then
playerslapped:FireServer(targetedplayer, humanoid, hit)
end
end
Nevermind, I found an alternative solution. If anyone wants to know what I instead use, I just added a debounce on the .Touched
event part.,
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.