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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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()
Ad

Answer this question