Trying to locally change a part’s transparency when a key is pressed but it doesn’t work. I found that all my code is working except for the actual change in transparency. I found a similar topic, and i copied the script that the solution supplied and it worked, but when I try to change the transparency nothing happens, I cant tell what the other script is doing, both of them are in starter player scripts.
Script from the topic i found, modified
local part_to_modify = workspace:WaitForChild("Baseplate")
local function modify(part)
part.Transparency = 1
wait(.1)
part.Transparency = 0
wait(.1)
part.Reflectance = 1
wait(.1)
part.Reflectance = 0
end
wait(10)
print("Modifying death barrier.")
modify(part_to_modify)
Script im making
Transparency = 0
DeathBarrier = workspace.Baseplate
Transparency = DeathBarrier.Transparency
local PlayerService = game:GetService('Players');
local UserInputService = game:GetService('UserInputService');
---------------------------------------------------------------------
UserInputService.InputBegan:Connect(function(keyPressed,currentlyOccupied)
if currentlyOccupied then return end
print (keyPressed.KeyCode)
if keyPressed.UserInputType == Enum.UserInputType.Keyboard then
if keyPressed.KeyCode == Enum.KeyCode.E then
print (Transparency)
Transparency = 0
end
end
end)
Are you using this code in a Server or Local script? UserInputService only works in the Local scripts. I ran your code in a Local Script under StarterPlayerScripts and the code works as intended.
i didnt get any errors unless im mistaking it for some other error.
the rest of the script wouldnt run anyway, im still getting outputs from me pressing keys.
I was unaware that you were using both scripts. I thought the first script was the script you found and the bottom was the edited version. I will reevaluate this.
Additionally your Variable is the baseplate transparency number. Meaning your your just changing the variable in the script and not changing the actual property