Need help with MouseClicks

  1. What do you want to achieve? I want to be able to do damage with a weapon without using a tool, I am in the process of making a system, but I’ve run into a problem.

  2. What is the issue? I get this in the output: 13:16:55.406 - Workspace.LukeCartoons.Script:2: attempt to index nil with ‘GetMouse’ . This script was originally designed for a local script, but I want it in the server side.

  3. What solutions have you tried so far?
    Is there a way I can track mouse clicks without using a click detector and without using gear?

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Anim = Instance.new('Animation')
Attacking = false
Sword = Player.Character.Technoblade

function Slash(hit)
	print(hit)
	Anim.AnimationId = "rbxassetid://5317422983"
	local playAni = Player.Character.Humanoid:LoadAnimation(Anim)
	playAni:Play()
	Sword.Touched:Connect(function(part)
		Hum = part.Parent:FindFirstChild("Humanoid")
		if Hum then
			Touch = true
		else
			Touch = false
		end
	end)
	if Touch == true then
		Hum.Health = Hum.Health - 10
	end
end


Mouse.Button1Down:Connect(Slash)

You have to get the mouse through the client not the server, the server cant access input and such, so your going to have to use something called a remote event which lets you speak between the client and the server, just pass over the mouse too the server script

You cannot and most definitely should not handle input on the server. Every button you press will feel the ping. Do everything input related client side as much as you can, only relay what you have to.
In this case, you can relay the touched event. Or handle the touched event on the server in a separate script.

Also, while we’re on the subject, you should never connect to the same event more than once. In this case, you want to create the event outside of the Slash function.

function slash()
    slash = true
    do stuff
    wait(.5)
    slash = false
end
touched:connect(function(hit)
    if slash then
        tell server damage is dealt
    end
end

Ok, I kinda understand, but why without a tool

If you just don’t want to see the tool gui then you should check this video:

The reason I am not using a tool is because I have the sword welded to the startercharacters arm, also I find using tools in pvp to be kinda scuffed, so I want to make a system where you just always have it out, also having the tool gui hidden would mess around with my future plans for this game.

You can use this function

Mouse.MouseButton1Down:Connect(function()
end)

It’s a script not a local script, so it won’t work

1 Like

Yeah thats why he needs to pass over mouse to the server

1 Like

yes, just use remote events and you’ll be fine, @LukeCartoons

alright, i’ll give it a try, thanks for the help! :slight_smile:

You can’t pass the mouse to the server. You can tell the server that the player clicked, but I’m serious, this is something you want to be handled locally as much as possible.