I need help with scripting real bad

I need help, i am a new scripter (Just started) and i need help with GUI appearing and dissapearing. It just doesn’t do the job right.

*local userInputService = game:GetService(“UserInputService”)

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)

if input.UserInputType == Enum.UserInputType.Keyboard then

		local Image = script.Parent.Parent.ImageLabel

if input.UserInputType == Enum.KeyCode.B then
local Image = script.Parent.Parent.ImageLabel.ImageTransparency = 0
then
local Image = script.Parent.Parent.ImageLabel.ImageTransparency = 1
end*

I appriciate anyone who can help.

1 Like

Put your code in a code block and go relearn if statements.

This code is incorrect and should be giving you exceptions.

local Image = script.Parent.Parent.ImageLabel.ImageTransparency = 1

You are not able to use two equal signs in lua like this.

It should be

local Image = script.Parent.Parent.ImageLabel
Iamge.ImageTransparency = 1

or

script.Parent.Parent.ImageLabel.ImageTransparency = 1

Thank you.
(30 words theng aebahrjg)

local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input,gp)
   if gp then return end
   if input.KeyCode== Enum.Keycode.B then
      local Image = script.Parent.Parent.ImageLabel
      Image.ImageTransparency = (Image.ImageTransparency == 0) and 1 or 0
   end
end
1 Like

I’d use luau ternary though since the regular lua ones aren’t exactly the most functional.

1 Like

There are multiple things wrong with the code

starting off with the use of

input.UserInputType === Enum.KeyCode.B

UserInpuType is the type of Input Device you use such as mouse button,keyboard so you need to ask for

input.KeyCode

and I think your trying to make it so if you press B it makes it visible but if you press something else it makes it transparent (thats what im getting off this)

you need to restructure your if statement to like this

if .. then

elseif ... then

else

end

so in here you’d go like this

  local Image = script.Parent.Parent.ImageLabel
  -- you declare your stuff first
if input.KeyCode == Enum.KeyCode.B then
  Image.ImageTransparency = 0
else 
  Image.ImageTransparency = 1

end

I’m sorry, it works fine just i’m trying to make it that after 3 seconds it dissapears, but it dissapears one second after.

what are u trying to do? send code

local userInputService = game:GetService(“UserInputService”)
userInputService.InputBegan:Connect(function(input,gp)
if gp then return end
local Image = script.Parent.Parent.ImageLabel
if input.KeyCode == Enum.KeyCode.B then
Image.ImageTransparency = 0
wait(3) else
Image.ImageTransparency = 1
end
end)

format ur code too please :nauseated_face:

local userInputService = game:GetService('UserInputService')

userInputService.InputBegan:Connect(function(input, typing)
	if typing then return end
	
	local Image = script.Parent.Parent.ImageLabel
	
	if input.KeyCode == Enum.KeyCode.B then
		Image.ImageTransparency = 0
		task.wait(3)
		Image.ImageTransparency = 1
	end
end)

Thank you.
(30 words aeaeaeaeaea)

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