So I want to be able to reference an image label but it's not working. Someone help.
Here is my code:
local imageLabel = game.StarterGui.ScreenGui.ImageLabel local UserInputSerivce = game:GetService("UserInputService") UserInputSerivce.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.M then imageLabel.Visible = true end end)
Note: StarterGui waits until a player joins, clones all of its contents, and moves all the cloned UI objects to the PlayerGui in the player object(This applies to all players in the server).
Insert a LocalScript into StarterPlayerScripts located in StarterPlayer.
In the script, write the following code:
local UserInputService = game:GetService("UserInputService") -- getting UserInputService local playerGui = game.Players.LocalPlayer.PlayerGui -- defining PlayerGui local imageLabel = playerGui:WaitForChild("ScreenGui"):WaitForChild("ImageLabel") -- make sure to define your ImageLabel because I don't know what your GUI hierarchy looks like. Just keep doing :WaitForChild() until you reach ImageLabel UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) -- gameProcessedEvent is basically used to check to see if the player is interferring with the engine EXAMPLE: The chat if input.KeyCode == Enum.KeyCode.M and not gameProcessedEvent then -- checks whether the player chatting imageLabel.Visible = true end end)
If you're having problems just reply and you'll get a response within 2 hours.