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