Button Keybind Isn't Working

Hello! So I’m trying to make a music game kind of like robeats, But the thing is the Keybind’s aren’t working, heres the script and heres the error

local ButtonItself = script.Parent
local TickClone = game.Workspace.LeftPlayerMainTick:GetChildren("LeftPlayerMainTickClone")

game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
	if key == "s" then -- Miss If The Player Just Clicks
		ButtonItself.Material = "Neon"
	else
		if key == "s" and TickClone.Position == Vector3(-1, 0.5, 16.5) or Vector3(-1, 0.5, 23.5) then -- Close If The Player Clicks and the Position Of The Clone Is Vector3(Position)
			ButtonItself.Material = "Neon"
		else
			if key == "s" and TickClone.Position == Vector3(-1, 0.5, 17) or Vector3(-1, 0.5, 23) then -- Great If The Player Clicks and the Position Of The Clone Is Vector3(Position)
				ButtonItself.Material = "Neon"
			else
				if key == "s" and TickClone.Position == Vector3(-1, 0.5, 17.5) or Vector3(-1, 0.5, 21) or Vector3(-1, 0.5, 18) or Vector3(-1, 0.5, 22) or Vector3(-1, 0.5, 18.5) or Vector3(-1, 0.5, 19.5) or Vector3(-1, 0.5, 20.5) then -- Great If The Player Clicks and the Position Of The Clone Is Vector3(Position)
					ButtonItself.Material = "Neon"
				else
					if key == "s" and TickClone.Position == Vector3(-1, 0.5, 20) then -- Epic If The Player Clicks and the Position Of The Clone Is Vector3(Position)
						ButtonItself.Material = "Neon"
					end
				end
			end
		end
	end
end)

Error

 08:55:31.315  Music Rush auto-recovery file was created  -  Studio - C:/Users/mrtix/OneDrive/Documents/ROBLOX/AutoSaves
  08:55:34.169  Workspace.LeftPlayerDetecter.Script:4: attempt to index nil with 'GetMouse'  -  Server - Script:4
  08:55:34.169  Stack Begin  -  Studio
  08:55:34.169  Script 'Workspace.LeftPlayerDetecter.Script', Line 4  -  Studio - Script:4
  08:55:34.170  Stack End  -  Studio
  08:55:57.397  0.5, 0.5  -  Server
  08:55:57.817  0.5, 0.5  -  Client
  08:56:43.885  Disconnect from ::ffff:127.0.0.1|64453  -  Studio
  08:58:11.277   ▶ Music Rush auto-recovery file was created (x2)  -  Studio - C:/Users/mrtix/OneDrive/Documents/ROBLOX/AutoSaves

GetMouse() is for mouse only, it’ll return nil only, instead, use UserInputService: UserInputService | Roblox Creator Documentation

2 Likes

Tried doing that and this kinda happened…

  10:06:04.018  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:04.019  Stack Begin  -  Studio
  10:06:04.019  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:04.019  Stack End  -  Studio
  10:06:04.928  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:04.930  Stack Begin  -  Studio
  10:06:04.931  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:04.932  Stack End  -  Studio
  10:06:06.443  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:06.443  Stack Begin  -  Studio
  10:06:06.444  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:06.444  Stack End  -  Studio
  10:06:06.959  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:06.960  Stack Begin  -  Studio
  10:06:06.960  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:06.961  Stack End  -  Studio
  10:06:07.742  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:07.743  Stack Begin  -  Studio
  10:06:07.743  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:07.744  Stack End  -  Studio
  10:06:07.878  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:07.878  Stack Begin  -  Studio
  10:06:07.878  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:07.879  Stack End  -  Studio
  10:06:08.560  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:08.561  Stack Begin  -  Studio
  10:06:08.561  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:08.562  Stack End  -  Studio
  10:06:08.944  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:06:08.944  Stack Begin  -  Studio
  10:06:08.945  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:06:08.945  Stack End  -  Studio

Here is the Updated Code,

local UserInputService = game:GetService("UserInputService")
local ButtonItself = game.Workspace.LeftPlayerDetecter
local TickClone = game.Workspace.LeftPlayerMainTick:GetChildren("LeftPlayerMainTickClone")

UserInputService.InputBegan:Connect(function(inputObject, gameProccessedEvent)
	if (inputObject.KeyCode == Enum.KeyCode.S) then -- Miss If The Player Just Clicks
		ButtonItself.Material = "Neon"
	else
		if (inputObject.KeyCode == Enum.KeyCode.S) and TickClone.Position == Vector3(-1, 0.5, 16.5) or Vector3(-1, 0.5, 23.5) then -- Close If The Player Clicks and the Position Of The Clone Is Vector3(Position)
			ButtonItself.Material = "Neon"
		else
			if (inputObject.KeyCode == Enum.KeyCode.S) and TickClone.Position == Vector3(-1, 0.5, 17) or Vector3(-1, 0.5, 23) then -- Great If The Player Clicks and the Position Of The Clone Is Vector3(Position)
				ButtonItself.Material = "Neon"
			else
				if (inputObject.KeyCode == Enum.KeyCode.S) and TickClone.Position == Vector3(-1, 0.5, 17.5) or Vector3(-1, 0.5, 21) or Vector3(-1, 0.5, 18) or Vector3(-1, 0.5, 22) or Vector3(-1, 0.5, 18.5) or Vector3(-1, 0.5, 19.5) or Vector3(-1, 0.5, 20.5) then -- Great If The Player Clicks and the Position Of The Clone Is Vector3(Position)
					ButtonItself.Material = "Neon"
				else
					if (inputObject.KeyCode == Enum.KeyCode.S) and TickClone.Position == Vector3(-1, 0.5, 20) then -- Epic If The Player Clicks and the Position Of The Clone Is Vector3(Position)
						ButtonItself.Material = "Neon"
					end
				end
			end
		end
	end
end)

Note that the LocalScript Is Inside of StarterPlayerScripts > PlayerScripts

Why do you have parantheses?

You should remove the “(” and ")"s, you don’t need those, just keep them as:

if inputObject.KeyCode == Enum.KeyCode.S then

And you don’t need gameProccessedEvent as a parameter, since I assume you’re not gonna use it. (currently not using)

2 Likes

Oops, I forgot to edit the script, I literally just pasted the same thing… :sweat_smile:

This should work;

1 Like

add this:

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end

i know it doesn’t help the question but you should always add this when you are doing something with keybinds

Use elseif instead of

else
    if

oh ye and u have to write

local UIS = game:GetService("UserInputService")

Thats not mandatory, I dont have to

Been added it in my update ver

1 Like

I dont know if

else 
    if

even works, using elseif is just a better practice and it may be the reason ur code isnt working

then you can just slap the code in i guess
(just so you know the code is making keybinds not work when player chatting

Heres the updated ver

local UserInputService = game:GetService("UserInputService")
local ButtonItself = game.Workspace.LeftPlayerDetecter
local TickClone = game.Workspace.LeftPlayerMainTick:GetChildren("LeftPlayerMainTickClone")

UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.S then -- Miss If The Player Just Clicks
		ButtonItself.Material = "Neon"
	else
		if inputObject.KeyCode == Enum.KeyCode.S and TickClone.Position == Vector3(-1, 0.5, 16.5) or Vector3(-1, 0.5, 23.5) then -- Close If The Player Clicks and the Position Of The Clone Is Vector3(Position)
			ButtonItself.Material = "Neon"
		else
			if inputObject.KeyCode == Enum.KeyCode.S and TickClone.Position == Vector3(-1, 0.5, 17) or Vector3(-1, 0.5, 23) then -- Great If The Player Clicks and the Position Of The Clone Is Vector3(Position)
				ButtonItself.Material = "Neon"
			else
				if inputObject.KeyCode == Enum.KeyCode.S and TickClone.Position == Vector3(-1, 0.5, 17.5) or Vector3(-1, 0.5, 21) or Vector3(-1, 0.5, 18) or Vector3(-1, 0.5, 22) or Vector3(-1, 0.5, 18.5) or Vector3(-1, 0.5, 19.5) or Vector3(-1, 0.5, 20.5) then -- Great If The Player Clicks and the Position Of The Clone Is Vector3(Position)
					ButtonItself.Material = "Neon"
				else
					if inputObject.KeyCode == Enum.KeyCode.S and TickClone.Position == Vector3(-1, 0.5, 20) then -- Epic If The Player Clicks and the Position Of The Clone Is Vector3(Position)
						ButtonItself.Material = "Neon"
					end
				end
			end
		end
	end
end)
  10:30:48.001  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:48.001  Stack Begin  -  Studio
  10:30:48.002  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:48.002  Stack End  -  Studio
  10:30:48.185  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:48.185  Stack Begin  -  Studio
  10:30:48.186  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:48.186  Stack End  -  Studio
  10:30:50.235  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:50.237  Stack Begin  -  Studio
  10:30:50.237  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:50.238  Stack End  -  Studio
  10:30:51.002  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:51.003  Stack Begin  -  Studio
  10:30:51.003  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:51.004  Stack End  -  Studio
  10:30:51.534  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:51.535  Stack Begin  -  Studio
  10:30:51.535  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:51.536  Stack End  -  Studio
  10:30:51.835  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:51.836  Stack Begin  -  Studio
  10:30:51.836  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:51.836  Stack End  -  Studio
  10:30:52.036  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:52.036  Stack Begin  -  Studio
  10:30:52.038  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:52.039  Stack End  -  Studio
  10:30:52.600  Players.NubblyFry.PlayerScripts.LeftDetecterHandler:9: attempt to call a table value  -  Client - LeftDetecterHandler:9
  10:30:52.600  Stack Begin  -  Studio
  10:30:52.601  Script 'Players.NubblyFry.PlayerScripts.LeftDetecterHandler', Line 9  -  Studio - LeftDetecterHandler:9
  10:30:52.601  Stack End  -  Studio

You cant pass a parameter to GetChildren()

2 Likes

Nevermind, I’m an idiot… :sweat_smile:
See @anirudh851 reply, you also need to use for loop if you want to loop thru the children to change the Vector3

1 Like

Confusion, Im not trying to move them, I was trying to make it so that hen the player click “R” on their keyboard then, The Pad Will light up

Whats a Parameter???


Screenshot 2021-06-23 130930

You’re using “or” wrong. you must specify it every “or”

if (inputObject.KeyCode == Enum.KeyCode.S) and TickClone.Position == Vector3(-1, 0.5, 16.5) or (inputObject.KeyCode == Enum.KeyCode.S) and TickClone.Position == Vector3(-1, 0.5, 23.5) then

end
or Vector3(-1, 0.5, 21) or Vector3(-1, 0.5, 18) or Vector3(-1, 0.5, 22) or Vector3(-1, 0.5, 18.5) or Vector3(-1, 0.5, 19.5) or Vector3(-1, 0.5, 20.5)

by doing that you’re confusing the script what do you mean by simply “vector3?” is what the script is basically getting.

and it’s erroring because its “vector3.new” not “vector3”

1 Like