2 of my scripts don't work, no errors

Alright, so…

I have two scripts that don’t work, even though they are supposed to so far I know.

Here’s the first one which I literally copied from a youtuber:

local minHeight = 10
local maxHeight = 30

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		local playerheight = nil
		local fallheight = nil

		if humanoid and humanoidRootPart then
			humanoid.FreeFalling:Connect(function(newState)
				if newState then
					playerheight = humanoidRootPart.Position.Y
					elseif not newState then
					fallheight = playerheight - humanoidRootPart.Position.Y

					if fallheight >= maxHeight then
						humanoid.Health = humanoid.Health - 100
					elseif fallheight >= minHeight then
						humanoid.Health = humanoid.Health - math.floor(fallheight)
					end

				end
			end)
		end
	end)
end)

and here is the problem child:

UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Shift = player.PlayerGui.ScreenGui.Shifttorun
	 
UserInputService:Connect(function(input)
	if input.Keycode == Enum.KeyCode.LeftShift then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
		print("TextTransparency has been changed.")
	end
	end)
	
UserInputService.InputBegan:Connect(function(input, gpe)--gpe checks if they are typing in chat
		if gpe then return end --Stops the script if they are typing in chat

		if input.Keycode == Enum.KeyCode.LeftShift then
			print("Pressed LeftShift")
		Shift.TextTransparency = 1
		print("TextTransparency has been changed 2.")
		end
	end)

I’ve already made a post about this one, asked for help in a discord server… gone through multiple fixes and still… doesn’t work.

Does anyone know what is going wrong?

UserInputService:Connect is not a function, try getting rid of that code block.

Do I put anything instead of that?

Nope InputBegan should work fine. Which you already have.

If I just delete that code block, input is an unknown global, otherwise:

UserInputService.InputBegan:Connect(function(input)
	if input.Keycode == Enum.KeyCode.LeftShift then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
		print("TextTransparency has been changed.")
	end
	end)

Using this doesn’t work.

Is this script in a local script > and where is the script located.

It’s a local, StarterPlayerScripts script.

Put it in starter character, starter pack, or start gui instead. Then test it.

All of them don’t work…
I’ve had other people tell me to put them in those places too, it doesn’t change anything for some reason…

Well you’re clearly doing something wrong then. Are both the scripts in 1 script like what are you doing wrong. I can go to studio and replicate this script and make it work right now. Like what are you specifically doing to prevent it from working.

I’m asking myself the same thing, and it’s probably the stupidest mistake.

And no they aren’t in the same script.

I can literally send you all my stuff if you want me to :sweat_smile:

oh wait found the error I think.

if input.Keycode == Enum.KeyCode.LeftShift then

KeyCode< not Keycode.

1 Like

Oh… I forgot about this :sweat_smile: :sweat_smile: :sweat_smile:

Keycode is not a valid member of InputObject “InputObject” - Client - LocalScript:17

I kept getting that, but other people didn’t know what was going wrong there.