:GetMouse() Not Working

I’m trying to make a sword skill but there is a problem is this script. It is a local script so :GetMouse() should work but it is not. It says that GetMouse is not a valid member of Players “Players”. Also, is there a way that I can have the skill only work if the sword is equipped right now you can activate the skill without the sword?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Error:
Screenshot 2024-03-13 224236

Code:

local player = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local cooldown = false
Mouse = player:GetMouse()
UIS.InputBegan:Connect(function(Input,Chat)
	if Chat then return end
	if Input.KeyCode == Enum.KeyCode.Z then
		cooldown = true
		print("skill Thrown")
		local mousepos = Mouse.Hit
		RS.SlashEvent:FireServer(mousepos,Mouse.Hit.p)
		local animation = player.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(script.SwordSlashAnim)
		animation:Play()
		game.Debris:AddIten(animation,2)
		task.wait(5)
		cooldown = false
	end
end)

Please help, I need to use this system for 100+ more attacks. I know this is not the best system but I’m bad at coding.

Change this

local player = game:GetService("Players")

to

local player = game:GetService("Players").LocalPlayer
2 Likes

thank you. Is there anything I can do about it only working when the sword is equipped?

it is now giving this error:
Screenshot 2024-03-13 225529

Nevermind I figured it out. I had to change

Mouse = player.:GetMouse()

to

Mouse = player.LocalPlayer:GetMouse()
local animation = player.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(script.SwordSlashAnim)

Change this to

local animation = player.Character:WaitForChild("Humanoid"):LoadAnimation(script.SwordSlashAnim)

As you already reference it, pretty much in that line you are doing LocalPlayer.LocalPlayer which doesn’t actually exist.

1 Like

thanks, but I figured it out, I showed what I did in the above comment.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.