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

it tryed the user input thing but it dose not do anying thing how do i fix?

local down = true
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local we = false
local wee = game:GetService("UserInputService")

wee.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.Q then
game.ReplicatedStorage.events.Fire:FireServer()
		
	end
end)

--mouse.KeyUp:Connect(function(key) -- lol i tryed keyheld ;-;
    --key = key:lower()
    --if key == "q" then
	wee.InputEnded:Connect(function(input)
	if input == Enum.KeyCode.Q then
		print("23")
game.ReplicatedStorage.events.Fire:FireServer()
		
game.ReplicatedStorage.events.metor:FireServer(game.Players.LocalPlayer:GetMouse())
	
end
end)

10 comments

0

can you tell me the errors please? (Check output)

0

thats the thing there is no error

0

it is a localscript right?

0

yeah

0

Okk I think I solved it

0

really?

0

Yes. I also had this problem a few days ago working in my game, so I know how to do it now

0

ok can u answer it?

0

I was writing the answer

0

You are trying to compare a InputObject to a KeyCode. You need to use the dot operator to access the InputObjects properties and scope to the KeyCode property. Hope you learned something.

2 answers

✓ Accepted answer

Hey. Your code is technically right, but it doesn't work for some reason. What you have to do is set a local value with the KeyCode and then check if the KeyCode is Q. It is explained better in this code.

local plr = game.Players.LocalPlayer
local InputService = game:GetService("UserInputService")

InputService.InputBegan:Connect(function(input)
    local key = input.KeyCode --Gets the key that the player pressed
	if key == Enum.KeyCode.Q then --Checks if the key is Q
		--Do whatever here
    end
end)

InputService.InputEnded:Connect(function(input)
    local key = input.KeyCode 
	if key == Enum.KeyCode.Q then
		--Do whatever here
	end
end)

I don't know why this error happens, but this is the way I solved it.

I hope I helped.

-VewixxPlayer

7 comments

0

Did this work?

0

Lol. I answered it before you but it is what it is lmao.

0

yeah

0

it doesn't matter who replied first

0

btw VewixxPlayer can u add me?

0

Never said it mattered its just funny to me.

0

what do u mean helleric? Roblox friends? If then yes. If there is a friend system on scriptinghelpers also yes xD

On line 8 and 18 you need to change:

if input == Enum.KeyCode.Q then

To the InputObject KeyCode property to compare key codes from the Input

if input.KeyCode == Enum.KeyCode.Q then

2 comments

0

hmm it worked but it spams

0

It spams because you arent using debounces or any boolean flags to wait for a x amount of time.

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