Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to effectively manipulate a player mouse inside of a tool?

Basically I am trying to make a arrest tool that will change the team of the player selected when the tool is activated. Here is the script I have created so far

--By: VineyardVine


local otherperson = nil
local otherhumanoid
mode = 1
sp = script.Parent
local me = game.Players.LocalPlayer

function changemode()
	if mode == 1 then
		mode = 2
		script.Parent.Name = "Release Mode"
	    elseif mode == 2 then
		mode = 1 
		script.Parent.Name = "Arrest Mode"
	end
end

function arrest()
	local target = Mouse.Target
	if target and target.Parent then
	local humanoid = target.Parent:FindFirstChild("Humanoid")
		if target.Parent:IsA("Hat") and target.Parent.Parent then
			humanoid = target.Parent.Parent:FindFirstChild("Humanoid")
		end
	if humanoid then
		otherperson = game.Players:GetPlayerFromCharacter(humanoid.Parent)
		otherhumanoid = humanoid
	end
	if otherperson and otherhumanoid and me:DistanceFromCharacter(humanoid.Parent.Head.Position) <= 5 and mode == 1 then
			otherperson.TeamColor = "Really black"
			otherhumanoid.Parent:BreakJoints()
		end
	end
end

function Equipped(mouse)
	Mouse = mouse
end

sp.Activated:connect(arrest)
sp.Equipped:connect(Equipped,changemode)

1 answer

✓ Accepted answer

You have your Mouse variable set up incorrectly. You can access a player's mouse via the LocalPlayer, rather than setting up an Equipped function.

local mouse = game.Players.LocalPlayer:GetMouse()

This discussion is preserved as it was. New answers, comments, and votes are closed.