I want to know how to detect the player if it’s close to a part, and if that player IS close to the part then I want to show a interaction GUI that when you press E it does something.
I don’t know how to make THAT work without the player being close to the part.
I am trying to make a hold E thing for turning on and off a light in my game and I need it to tween a progress bar.
How would I make the hold E thing work too because I have the code in my head. The code in my head that goes into the UserInputService thing is:
local thing = coroutine.create(function()
while wait() do
if notHoldingE then
notHoldingE = false
else
notHoldingE = true
break
end)
coroutine.resume(thing)
tween:Play()
wait(3)
-- Lights on
local inputServ = game:GetService("UserInputService")
local dist = 5
local isKeyDown = false
local e = coroutine.create(function()
while wait() do
if (game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position - workspace.Part.Position).Magnitude < dist then
script.Parent.Parent.Parent.e.Visible = true
else
script.Parent.Parent.Parent.e.Visible = false
end
end
end)
local r = coroutine.create(function()
while wait() do
if (game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position - workspace.Part.Position).Magnitude < dist then
local isKeyDown = inputServ:IsKeyDown(Enum.KeyCode.E)
else
local isKeyDown = false
end
end
end)
coroutine.resume(e)
coroutine.resume(r)
while wait() do
if isKeyDown then
print("HOLDING E")
end
end
The GUI shows the E thing in the corner BUT… it doesn’t print “HOLDING E” when I am holding E when I am close enough to it.
while wait() do
if isKeyDown then
script.Parent.Parent.Visible = true
tween:Play()
wait(2)
print("Hi")
else
tween:Cancel()
script.Parent.Parent.Visible = false
script.Parent.Size = UDim2.new(0, 0, 1, 0)
end
end
How would I make it stop the running the code in the top part of the if?
while wait() do
if isKeyDown and a variable == true then
script.Parent.Parent.Visible = true
the variable = false
tween:Play()
wait(2)
print("Hi")
elseif not isKeyDown then
tween:Cancel()
script.Parent.Parent.Visible = false
script.Parent.Size = UDim2.new(0, 0, 1, 0)
The variable =true
end
end
No like I need the actual script because I can’t get my head around this.
Here is the current script I have right now with that in it.
local inputServ = game:GetService("UserInputService")
local tweenServ = game:GetService("TweenService")
local dist = 5
local isKeyDown = false
local tweenInf = TweenInfo.new(2)
local tween = tweenServ:Create(script.Parent, tweenInf, {Size = UDim2.new(1, 0, 1, 0)})
local e = coroutine.create(function()
while wait() do
if (game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position - workspace.Part.Position).Magnitude < dist then
script.Parent.Parent.Parent.e.Visible = true
else
script.Parent.Parent.Parent.e.Visible = false
end
end
end)
local r = coroutine.create(function()
while wait() do
if (game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position - workspace.Part.Position).Magnitude < dist then
isKeyDown = inputServ:IsKeyDown(Enum.KeyCode.E)
else
isKeyDown = false
end
end
end)
coroutine.resume(e)
coroutine.resume(r)
while wait() do
if isKeyDown then
script.Parent.Parent.Visible = true
tween:Play()
wait(2)
print("Hi")
elseif not isKeyDown then
tween:Cancel()
script.Parent.Parent.Visible = false
script.Parent.Size = UDim2.new(0, 0, 1, 0)
end
end