Help with Space in UserInputService

How How would i put it so it detects a space? I tried “space” and “32” but it wouldn’t work.

local userInputService = game:GetService("UserInputService")
local key = 'space'
local RunService = game:GetService("RunService")


--Script
local coolDown = true

		userInputService.InputBegan:Connect(function(Input, IsTyping)


			if IsTyping then return end
			local keyPressed = Input.KeyCode

			if keyPressed == Enum.KeyCode[key] and coolDown and script.Parent.Text == "space" then

				coolDown = false

				script.Parent.Parent.Tool.ImageColor3 = Color3.fromRGB(216,0,0)

				local time = 4
				while wait(1) do
					if time == 0 then
						script.Parent.Text = 'Space'
						script.Parent.Parent.Tool.ImageColor3 = Color3.fromRGB(255,255,255)
						break
					else
						script.Parent.Text = tostring(time) --sets onscreen gui timer
						time = time - 1
					end
				end

				coolDown = true

			end

		end)

with user input service you should be using ‘Enmum.Keycode.Space’
This is the enum of the space key (The core spacebar button across Roblox’s user interface)

The same can be used for console controllers or keyboards.

1 Like