Have problem with script

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)
1 Like

MouseClick is an event, not a boolean.

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!

1 Like

But how to define second player.

Can I use there :GetPlayer to define 2nd plr?

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)


And how to transport that 2nd player to server script then ot it is transported when is called onserverevent?

local Remote = --remote here


Remote.OnServerEvent:Connect(function(PlayerThatCalled,PlayerToFreeze)
	
end)