Please help me! The output says " bad argument #2 to '?' (string expected, got Object) "
1 | local plr = game:GetService( "Players" ) |
2 | local mouse = plr:GetMouse() |
3 | local text = script.Parent.TextLabel |
4 |
5 | mouse.KeyDown:connect( function (key) |
6 | text.Text = key |
7 | end |
This is because the Mouse.KeyDown
event is deprecated. Instead, use the UserInputService
.
1 | local text = script.Parent.TextLabel |
2 |
3 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input, chatting) |
4 | text.Text = tostring (input.KeyCode) |
5 | end ) |
That's because you forgot the LocalPlayer
after game:GetService("Players")
1 | local plr = game:GetService( "Players" ).LocalPlayer --here |
2 | local mouse = plr:GetMouse() |
3 | local text = script.Parent.TextLabel |
4 |
5 | mouse.KeyDown:Connect( function (key) --use uppercase Connect |
6 | text.Text = key |
7 | end |
Although as incapaz mentioned, you should use UserInputService
instead.