Hello. I made a Press ‘E’ part like those in popular games (Jailbreak, Mad City, etc). But for some reason, nothing, but literally nothing happens. The output does not return anything, here is my code:
local billboardGui = script.Parent;
local inside = billboardGui.Inside;
local userInputService = game:GetService("UserInputService");
local function input_Began(input, isTyping)
if isTyping then return end
if (workspace.CurrentCamera.CFrame.Position - script.Parent.Parent.Position).Magnitude < script.Parent.MaxDistance then
return
end
local keyCode = input.KeyCode;
if keyCode.KeyCode == Enum.KeyCode.E then
currentTime = tick()
inside.Visible = true
local tweenService = game:GetService("TweenService");
local tweenInfo = TweenInfo.new(1.98);
local goal = {
Size = UDim2.new(0.67, 0,0.604, 0);
}
finalTween = tweenService:Create(inside, tweenInfo, goal)
finalTween:Play()
else
return
end
userInputService.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E then
if math.floor(tick()) - math.floor(currentTime) > 1.99 then
inside.Visible = false
inside.Size = UDim2.new(0.297, 0,0.275, 0)
warn("In time")
else
finalTween:Stop()
inside.Visible = false
inside.Size = UDim2.new(0.297, 0,0.275, 0)
return
end
end
end)
end
userInputService.InputBegan:Connect(input_Began)
Any help?
Heres a example of how an inputservice with E works :E Door.rbxl (38.7 KB)
Hope this helps u out^^ else ask me on Discord : OfficialSpy#0001 , im not really into reading DevForum.
I don’t believe there is a ‘working’ or ‘right’ way of making something. As long as the method you are using is possible to use when creating the thing you are looking to create, it can be considered right. Beyond that, do you find any error in my code?
Could you send me the thing so I can test? |( Private Message me on DevForum if u don’t have Discord )|
1 Like
As I’ve already explained in the post, there’s nothing much to see. The output doesn’t return anything and nothing is really working. I do not think it’s that necessary to send a place copy, if you find it truthfully necessary, I’d create a place-copy and share the file here.
nvm I found ur problem.
local keyCode = input.KeyCode;
if keyCode.KeyCode == Enum.KeyCode.E then
U trying to get KeyCode from KeyCode. In ur script it should be keyCode == Enum.Keycode.E
UserInputService is not only detecting KeyBoard inputs (button presses), but other inputs as well.
Input returns the input itself, so I got the KeyCode input from the input that it returned. I have tried to remove input.KeyCode
to input
and it did not effect anything. Any other thing you see in my code?
But why are you providing a variable for the input’s keycode? I see no reason. It just occupies a line of code.
Use this code:
local billboardGui = script.Parent;
local inside = billboardGui.Inside;
local userInputService = game:GetService("UserInputService");
local function input_Began(input, isTyping)
if isTyping then return end
if (workspace.CurrentCamera.CFrame.Position - script.Parent.Parent.Position).Magnitude < script.Parent.MaxDistance.Value then
return
end
local keyCode = input.KeyCode;
if input.KeyCode == Enum.KeyCode.E then
currentTime = tick()
inside.Visible = true
local tweenService = game:GetService("TweenService");
local tweenInfo = TweenInfo.new(1.98);
local goal = {
Size = UDim2.new(0.67, 0,0.604, 0);
}
finalTween = tweenService:Create(inside, tweenInfo, goal)
finalTween:Play()
else
return
end
end
userInputService.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E then
if math.floor(tick()) - math.floor(currentTime) > 1.99 then
inside.Visible = false
inside.Size = UDim2.new(0.297, 0,0.275, 0)
warn("In time")
else
finalTween:Stop()
inside.Visible = false
inside.Size = UDim2.new(0.297, 0,0.275, 0)
return
end
end
end)
userInputService.InputBegan:Connect(input_Began)
I find it more helpful to use variables, considering it makes it more readable to my eyes.
Tried it, it didn’t work. Anything else?
If this doesn’t work pls , send me a screenshot of how ur UI/GUI looks like bc I don’t know if
script.Parent.MaxDistance is a Value or sth else.^^ but ig u forogt to use MaxDistance.Value.
And pls send the Error output.
If this is something involving bars, the method :TweenPause()
is more recommended, unless it’s intended for the tween’s progress to actually be reset.
I take the MaxDistance property of the BillboardGui.
Both methods (the method that you provided and the method that I used in my code) will do the same thing.
hmm btw what is script.Parent.Parent.Position? where is the script inside at.
What method you used was :Stop()
, not :Pause()
. Using :Stop()
will erase the progress of the tween when playback is called again. When using :Pause()
the playback of the tween and its progress is halted, but when played again it will continue playback.
1 Like
Here is a screenshot from how it looks (objects were marked):
What exactly is the problem? What isn’t happening that’s supposed to happen?
Kk heres my solution for u:
Put that Billboardgui inside Startergui, put that Billboardgui.Adoorne to the part and use BillBoardGui.Adoorne.Position