I am creating a Time stop game but I need to use key code my script is currently:
local UIS = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local hum = plr.Character:WaitForChild("Humanoid") UIS.InputBegan:Connect(function(input, gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then print("Key:",input.KeyCode) wait(1) if input.UserInputType == Enum.KeyCode.T then print("T was pressed at", input.Position) local Timestop = workspace:WaitForChild("Timestop") repeat Timestop.Size = Vector3(Timestop.Size+1, Timestop.Size+1, Timestop.Size+1) wait(0.1) until Timestop.Size == Vector3(190, 190, 190) end wait(60) end end)
and I have it in Starter Character Scripts
The only output I am getting is ? Key: Enum.KeyCode.T - Client - LocalScript:7
Any help?
input.UserInputType == Enum.KeyCode.T Will never work because UserInputType only works for checking mouse clicks and keyboards types Use input.KeyCode == Enum.KeyCode.T Or better yet use ContextActionService :)
I noticed two errors. When you want to change the size of a 3D object it should be written as:
object.Size = Vector3.new(x,y,z) -- Value you want
Also I noticed that the if statement was wrong, you shouldn't check the enum, you should check the name or value of the keycode.
So the code should look like this:
local UIS = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local hum = plr.Character:WaitForChild("Humanoid") UIS.InputBegan:Connect(function(input, gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then print("Key:",input.KeyCode) wait(1) if input.KeyCode.Name == "T" then -- https://create.roblox.com/docs/reference/engine/enums/KeyCode print("T was pressed at", input.Position) local Timestop = workspace:WaitForChild("Timestop") repeat Timestop.Size = Vector3.new(Timestop.Size.X + 1 , Timestop.Size.Y + 1, Timestop.Size.Z + 1) task.wait(0.1) until Timestop.Size == Vector3.new(190, 190, 190) task.wait(60) end end end)
https://create.roblox.com/docs/reference/engine/enums/KeyCode https://create.roblox.com/docs/reference/engine/classes/BasePart#Size https://create.roblox.com/docs/reference/engine/datatypes/Vector3