I want to make that if player1 have equiped tool and clicked player2 (for example who has clickdetector) then that player2’s humanoidrootpart will be anchored for 5 seconds. The script is LocalScript and located in the tool. I’ve tried to make it but no result.
Script:
local tool = script.Parent.Parent
tool.Activated:Connect(function()
local detected = game.Workspace.Parent
if detected:FindFirstChild("VenomDetector").MouseClick then
detected.HumanoidRootPart.Anchored = true
task.wait(5)
detected.HumanoidRootPart.Anchored = false
end
end)
You could try having a LocalScript inside the tool that fires a RemoteEvent and tells the server the tool was activated.
local tool = script.Parent
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local function processClick()
if not mouse.Target then return end
if mouse.Target:IsDescendantOf(--[[Player 2's Character]]) then
RemoteEvent:FireServer()
end
end
tool.Activated:Connect(processClick)
This is untested so I’m not sure if it would work. Hope it helps!
You can get the second player by using this code here. Make sure you replace “youreventHere” with the event that you have. Hope this helps!
local tool = script.parent
local PlayerMouse = game:GetService("Players").LocalPlayer:GetMouse()
tool.Activated:Connect(function()
if PlayerMouse.Target ~= nil then
local Character = PlayerMouse.Target:FindFirstAncestorOfClass("Model")
if Character:FindFirstChildOfClass("Humanoid") then
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Character == Character then
game:GetService("ReplicatedStorage").youreventHere:FireServer(v)
end
end
end
end
end)