Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my transparency script not working when i press a key?

Asked by 6 years ago

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)
0
Is this is a local script? happytimeroblox101 36 — 6y

1 answer

Log in to vote
0
Answered by
atawok 33
6 years ago
Edited 6 years ago

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:

  • InputBegan: when an input begins, such as pressing a key down.
  • InputEnded: when an input ends, such as letting go of said key.
  • InputChanged: when an input is changed, useful for things like mouse movement.

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

0
No real explanation = bad answer. User#25115 0 — 6y
0
Sorry for so many edits, just getting used to the site. Also Phlegethon I've elaborated quite a bit. atawok 33 — 6y
Ad

Answer this question