TextTransparency isn't changing

Before I start:
I know that there are other topics that are identical to this, but I just can’t find out how to fix this.

So I’ve been hammering at this for an hour already but I still can’t find out what is going wrong,
I’ve gone through multiple versions of this code to get the result I want which is:
“Player presses shift → TextLabel gone.”
but it still doesn’t work and just leaves me dumbfounded since I know it’s so simple.

The code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Shift = game.StarterGui.ScreenGui.Shifttorun
	 
mouse.KeyDown:connect(function(key)
	if key == "LeftShift" then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
	end
end)

Location of Shifttorun:
image

Text properties of Shifttorun:
image

If anyone knows what is going on, fixing it would be appreciated.

(Maybe I’m just being a tired idiot)

You are using StarterGui and not PlayerGui. StarterGui is what gets cloned to the client when they join the game. You should use PlayerGui instead because its the GUI the player actually sees. Also, mouse.KeyDown is deprecated. Use UserInputService | Roblox Creator Documentation and UserInputService | Roblox Creator Documentation. Lmk if you need further help.

If you don’t understand look in the explorer in studio. You’ll see that StarterGui is a service in there. If you press the play button and spawn, look inside the player object (game.Players.DarknessDo123) and you’ll see PlayerGui.

1 Like

Sorry for not replying quickly but I’m searching for info on UserInputService.
So:

UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Shift = game.StarterGui.ScreenGui.Shifttorun
	 
UserInputService.InputBegan:Connect(function(input)
	if input.Keycode == Enum.KeyCode.LeftShift then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
	end
end)

If I put this in a PlayerGui, would it work?

Wait… I’m stupid…

I should do this:

UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Shift = game.PlayerGui.ScreenGui.Shifttorun
	 
UserInputService.InputBegan:Connect(function(input)
	if input.Keycode == Enum.KeyCode.LeftShift then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
	end
end)

Correction:
game.Players.LocalPlayer.PlayerGui.Shifttorun

1 Like

Seems like I need some rest…

:sweat_smile:

Yea that’s good just make sure to replace the part that the other person said.

Also, InputBegan comes with another parameter that, to simplify, checks if they are typing in chat or not.

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
   end
end)

You should always add these so InputBegan doesn’t fire unnecessarily.

1 Like

So it should be like this?

UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Shift = game.Players.LocalPlayer.PlayerGui.ScreenGui.Shifttorun
	 
UserInputService.InputBegan:Connect(function(input)
	if input.Keycode == Enum.KeyCode.LeftShift then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
	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
		end
	end)
end)

It doesn’t seem to make the Shifttorun dissapear though…

It may have something to do with me running another script that uses LeftShift:

-- INFO you can change --
local speed = 20 -- how fast you want the player to sprint?
local norm_spd = 12 -- what do you want the normal speed to be?
local ke_y = Enum.KeyCode.LeftShift -- what key do you want it to work with?


------------------------------------------------ Don't edit under here - you may break something -- --
local fovMax = { FieldOfView = 90 + (speed/5) }
local fovMin = { FieldOfView = 70 }
local thing = game.Workspace.CurrentCamera
local tween = game.TweenService:Create(thing, TweenInfo.new(0.4, Enum.EasingStyle.Sine), fovMax)
local tween2 = game.TweenService:Create(thing, TweenInfo.new(0.4, Enum.EasingStyle.Sine), fovMin)
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, processed)
   if processed then return end
   if input.UserInputType == Enum.UserInputType.Keyboard then
   		if input.KeyCode == ke_y then
       		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = speed
			tween:Play()
			-- tween starts 1 and stops 2
   		end
	end
end)

UIS.InputEnded:Connect(function(input) 
	if input.KeyCode == ke_y then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = norm_spd
		tween2:Play()
		-- tween starts 2 and stops 1
	end
end)

It should work regardless if another script. I see that you’re missing an end) in the first connection which is the problem. Not sure if that’s a paste issue or not.

1 Like
UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Shift = game.Players.LocalPlayer.PlayerGui.ScreenGui.Shifttorun

UserInputService.InputBegan:Connect(function(input)
	if input.Keycode == Enum.KeyCode.LeftShift then
		print("Pressed LeftShift")
		Shift.TextTransparency = 1
	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
		end
	end)

Like this?
It doesn’t work…
Sorry if I did something wrong again.