So, i am trying to make a script where when you press e some objects hove 0 transparency, for some reason this script wont work. Why?
Here is the script, it is local and it is in Starter pack.
repeat wait() until game.Players.LocalPlayer local player = script.Parent.Parent local mouse = player:GetMouse() mouse.KeyDown:connect(function(key) if key == "e" then game.Workspace.eno.Transperency = 0 game.Workspace.owt.Transperency = 0 game.Workspace.eerht.Transperency = 0 game.Workspace.ruof.Transperency = 0 end end)
Use UserInputService, also you were spelling 'Transparency' incorrectly.
UserInputService, somewhat like ContextActionService, will provide you a way to detect all sorts of input on the client. It includes events such as:
All of these events can be connected to a function with an "input" argument, which you'll use to check what kind of input is being received, as well as the optional boolean "gameProcessedEvent." gameProcessedEvent will be true if the input is being handled elsewhere in the game, such as typing in the chat.
Values of input can be checked using the Enum library, such as Enum.KeyCode
Here is a solution that will work for you:
local player = game.Players.LocalPlayer local userInput = game:GetService("UserInputService") userInput.InputBegan:Connect(function(input, processed) if not processed and input.KeyCode == Enum.KeyCode.E then game.Workspace.eno.Transparency = 0 game.Workspace.owt.Transparency = 0 game.Workspace.eerht.Transparency = 0 game.Workspace.ruof.Transparency = 0 end end)
Keep in mind, if you want the Transparency changes to replicate to the server and other clients, you'll need to use RemoteEvents/RemoteFunctions and change the transparency in a server script.
More can be learned about UserInputService/Enums here: https://developer.roblox.com/api-reference/class/UserInputService https://developer.roblox.com/api-reference/enum/KeyCode https://developer.roblox.com/api-reference/enum/InputType