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

My keybind script wont work for some reason. "attempt to index nil with 'GetMouse"?

Im trying to make it so when a player presses "t" they get a Value for the exp i have

game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
	if key == "t" then
		game.Players.Experience.Value = game.Players.Experience.Value + 100000
	end
end)


but i keep getting this error "attempt to index nil with 'GetMouse"

2 comments

0

You should use UserInputService instead of mouse.KeyDown

0

Us this local script? UserInputService/Mouse isn't defined on server scripts

1 answer

✓ Accepted answer

Using the mouse for keybinds is old, I recommend using UserInputService.

Here's your script but user input service related.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input)
	if UserInputService:GetFocusedTextBox() then
		return
	end
	if Input.KeyCode == Enum.KeyCode.T then
		game.Players.Experience.Value = game.Players.Experience.Value + 100000
	end
end)

Note: This must be a local script or it will not work.

3 comments

0

If there's any errors or questions, let me know.

0

it works it just doesn't lvl up the character normally i had a block that would do the same thing as the script you just sent in. The block i had up the value like the script u sent in and it "levels

0

levels up the player but the number just keeps adding on

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