I am trying to make a script that when a player is close enough they press "E" on their keyboard and a c4 device appears on an entry point. (The parts I change the transparency of). But when I test it, nothing happens. Any idea why?
Heres the code..
function onKeyPress(inputObject, gameProcessedEvent)
end
local radius = 25
for _, v in pairs(game.Players:GetPlayers()) do
if v:DistanceFromCharacter(script.Parent:GetModelCFrame().p) < radius then
if inputObject.KeyCode == Enum.KeyCode.E then
script.Parent.Union.Transparency = 0
script.Parent.Part1.Transparency = 0
script.Parent.Part2.Transparency = 0
script.Parent.Part3.Transparency = 0
script.Parent.Part4.Transparency = 0
script.Parent.Part5.Transparency = 0
script.Parent.Part6.Transparency = 0
script.Parent.Part7.Transparency = 0
script.Parent.BillboardGui.Frame["Bomb Placement"].visible = false
end
end
end
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)

4 comments
Your code is outside of the onKeyPress function. Use a for loop to make all the parts in script.Parent Transparent instead.
I understand what your saying, don't know how to implement it. Im still very new lol
If you are using a "ServerScript" You need to use a "LocalScript" for use "UserInputService"
Ah thank you