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

GetMouse:() Doesn't work with tools?

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

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

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