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

Time Stop:GunGame How to use Kaycode to change the size?

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?

4 comments

0

Hi can you put the rest of your code in a code block. Some of it is already, but can you put the rest in one.

0

I dont know how to

0

done

0

Hope my answer works for you!

2 answers

✓ Accepted answer

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

3 comments

0

I don’t understand why are you not doing Input.KeyCode == Enum.KeyCode.T it’s how Roblox does it

0

It's the same thing as doing input.KeyCode.Name == "T" or input.KeyCode.Value == 116

0

its better to do Input.KeyCode == Enum.KeyCode.T so there wont be any problems if roblox changes the name of each Keycodes

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