UIS.InputBegan function not firing?

Hello! I have made a code for a GUI at the start of my game, everything seems to be working fine EXCEPT the ‘UIS.InputBegan’ function in the script.


I have put ‘print(“”)’ between ‘UIS.InputBegan’ and ‘if Input.KeyCode’ and it printed but when i put ‘print(“”)’ inside of ‘if Input.KeyCode’ nothing happens? I have also tried ‘Input.UserInputType’ but still nothing.

this is a very common issue and i’ve read it everytime.
from what i see, i assume you’re using a basic script. since you’re using Players.PlayerAdded.
UserInputService doesn’t fire InputBegan for normal scripts, because it’s for an entire server, and not a single player. so, you should move the UserInputService handler to a localscript inside StarterPlayerScripts.

2 Likes

Yea that’s something i forgot to mention, it already is a LocalScript i just didn’t put it in StarterPlayerScripts. But even then it still won’t work?

Do you have any errors? Please, send the script and its type (Local, Server, Script where RunContext=Client) to understand what the problem is.

Why are you accessing every player’s PlayerGui from the client? Everyone else’s PlayerGui is not replicated to other clients

Well then how can i access the player’s GUI?

Here’s the script (Local Script).
StartingScreen.lua (1.3 KB)

Also no i don’t get any errors.

Players.LocalPlayer.PlayerGui

1 Like

It still doesn’t work for some reason.

If it’s a server script then you can’t access the UserInputService, if it’s a local script then you can’t access other player’s GUIs. Your LOCAL script should be something like this:

local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local MainGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui")
local SB64 = MainGui.SB64
local Dark = MainGui.Darkness
local Bright = MainGui.Brightness
local T1 = TS:Create(Dark, TI, {BackgroundTransparency = 1})
local T2 = TS:Create(Bright, TI, {BackgroundTransparency = 0})
local T3 = TS:Create(Bright, TI, {BackgroundTransparency = 1})
Bright.Visible = false
SB64.Visible = true
Dark.Visible = true
task.wait(1)
T1:Play()
-------------------
T1.Completed:Wait()
-------------------
Dark.Visible = false
UIS.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.ButtonStart then
			Bright.Visible = true
			T2:Play()
			-------------------
			T2.Completed:Wait()
			-------------------
			SB64.Visible = false
			task.wait(1)
			T3:Play()
			-------------------
			T3.Completed:Wait()
			-------------------
			Bright.Visible = false
		end
	end)
1 Like

Wait, so i don’t need the PlayerAdded part?

1 Like

No! You need to place this LOCALscript in StarterPlayerScripts. So that each player has his own script and his own gui, since the server cannot access the UserInputService

1 Like

Local scripts in StarterPlayerScripts will already run for each player that logs into your game, but locally so you would use just one Players.LocalPlayer instead of iterating over :GetPlayers()

It still won’t work, even though i followed your instructions.

If you modified anything from @3YbuKtOp’s script can you post your modified version? Were there any errors in the output? How did it fail? what were you expecting it to do?

1 Like

Have an error? I typed quickly so maybe I missed something.

1 Like

Nevermind, it works now! Thanks for your help.

It works now. Thanks for your help. :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.