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

Space bar input doesn't work but other keys do?

This local script has an input key but space isnt working, help?

local mouse = game.Players.LocalPlayer:GetMouse() 

mouse.KeyDown:connect(function(key) 
	if key:lower() == "space" then 
		local make = Instance.new("Part", game.workspace)
		make.Name = "MoreDash"
		make.Anchored = true

		local playerPos = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
		print(playerPos)
		make.Size = Vector3.new(3, 1, 3)
		make.Position = Vector3.new(playerPos.X, playerPos.Y, playerPos.Z) 
		make.Position = make.Position - Vector3.new(0, 3, 0) 
	end 
end)

2 answers

✓ Accepted answer

mouse.KeyDown is deprecated. Use UserInputService instead.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, GPE)
	if GPE then return end --There is a CoreGui event (like chatting) then do nothing. This is one of the advantages of UIS.
	if input.KeyCode == Enum.KeyCode.Space then
		local make = Instance.new("Part", game.workspace)
       		make.Name = "MoreDash"
	        make.Anchored = true

        	local playerPos = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
	        print(playerPos)
	        make.Size = Vector3.new(3, 1, 3)
        	make.Position = playerPos --You don't need to do the X Y Z part. It's already defined.
	        make.Position = make.Position - Vector3.new(0, 3, 0) 
	end
end)

2 comments

0

pretty good but could be changed a bit

0

tysm

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