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

The UserInputService isn't working?

I did everything correct below?:(local script btw)

local UIS = game:GetService("UserInputService") local key = "E" -- key

UIS.InputBegan:Connect(function(input, gameProccessedEvent) if gameProccessedEvent then return end if input.Keycode = Enum.Keycode.E then print("Worked!") end end

1 comment

0

btw its == enum i forgot to put that

2 answers

https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan

Read this. It should explain how to use InputBegan with code demonstration.

Also, next time try to use a code block when putting code like this -

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Clone = game.ReplicatedStorage.ImportantCharValues:Clone()
		Clone.Parent = char
		
		local ChClone = game.ReplicatedStorage.CharVariables:Clone()
		ChClone.Parent = char 
	end)
end)

When making an "if" statement, you are trying to find out what something equals.

Your problem can be seen below

When setting a value, you would use an '=' like so:

Script.Parent.Value = 5
--or
Script.Parent.Value = Script.Parent.Value + 5

Now you should see the problem in your 'if' statement. You are trying to set a value.

To check a value, you would use '==' as seen below

local Val = script.Parent

Val.Value = Val.Value + 1

if Val.Value == 5 then
   Print("true")
end

Now let's fix your code

if Input.KeyCode == Enum.KeyCode.E then

This is the line that you should fix.

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