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

GetMouse:() Doesn't work with tools?

Asked by 8 years ago

I'm having some trouble with this custom swordscript that I'm working on. It works in test servers/play solo, however not in an actual game. The game is filteringenabled, and the script is inside the tool. I need to be able to get the mouse because I have an option for RightClicking to do a RightSlash/Combo move. Here's the script:

tool = script.Parent

function onEquip()
char = tool.Parent
player = game.Players:GetPlayerFromCharacter(char)
wait(0.2)
mouse = player:GetMouse()
mouse.Button1Down:connect(function() leftslash(mouse) end)
mouse.Button2Down:connect(function() rightslash(mouse) end)
end

tool.Equipped:connect(onEquip)

1 answer

Log in to vote
0
Answered by 8 years ago

SO! The problem is NOT with the GetMouse function. However, there is a bit of an efficiency upgrade we can do by just getting the mouse from the equipped event:

tool = script.Parent

//Just get the mouse from the equipped event!
function onEquip(mouse)
    wait(0.2)
    mouse.Button1Down:connect(function() leftslash(mouse) end)
    mouse.Button2Down:connect(function() rightslash(mouse) end)
end

tool.Equipped:connect(onEquip)

Your original code should work fine as well, but this is a bit neater.

A few other things, make sure that you are invoking the RemoteFunction properly. That's what you have to do with FilteringEnabled games. So if the leftslash/rightslash functions are in this script here, it will NOT work. Make sure it looks like this:
local leftslash = game.Workspace.leftslash:InvokeServer(mouse) where Workspace.leftslash is your RemoteFunction.

In your RemoteFunction, make sure you have a script like this:

//The player variable is the player that invoked the the function. It's automatically added.
function script.Parent.OnServerInvoke(player, mouse)
    //Insert Code Here
end

oooorrrr maybe you already knew this.

At least, it isn't a problem with :GetMouse().

Ad

Answer this question