My E interaction script isn't working

Nothing is happening, literally nothing as I already noted. I think something may be yielding my code. Do you find anything that you suspect could be yielding my code?

Try using prints across the code inbetween or inside events and see if anything is printed out. Tell me afterwards.

Edit: Why is the InputEnded event inside the InputBegan function? You should make a separate function for the InputEnded event. This could be one of the things yielding your code, or, maybe your code is running, but it suddenly goes to the InputEnded event.

1 Like

I made a different thing that is like urs.
grafik
https://gyazo.com/5c4d247bbe494c09eee82cb14d3a29c5
local billboardGui = script.Parent;

local inside = billboardGui.Adornee

Summary
local userInputService = game:GetService("UserInputService");

local function input_Began(input, isTyping)
	
	if isTyping then return end
	
	if (workspace.CurrentCamera.CFrame.Position - billboardGui.Adornee.Position).Magnitude < script.Parent.MaxDistance then
		
		return
	end
	
	local keyCode = input.KeyCode;
	
	if input.KeyCode == Enum.KeyCode.E then
		
		currentTime = tick()
		
		inside.BrickColor = BrickColor.new("Black")
		
		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)

The could-be problem here is the InputEnded event being put inside the InputBegan function. This isn’t exactly what OP is looking for.

I didn’t make it like that ^^ , I just fixed his Code a bit aka tried giving him a solution on how to fix it.

I did remove the InputEnded before from Inputbegan function :wink:

That won’t work; the CurrentTime variable is inside the scope of the InputBegan event. The variable should be declared at the start before doing anything else - then it can be used like as if it were a global variable.

@XDvvvDX found the culprit. You’re supposed to put > instead of <, or else it can only be accessed at far distances.

-------------
--- INDEX ---
-------------

--// DECLARABLES
local uis = game:GetService("UserInputService");
local bGui = script.Parent;
local inside = bGui.Inside;

local CurrentTime;
---------------------
--- INTIALIZATION ---
---------------------

local tween = game:GetService("TweenService"):Create(inside, TweenInfo.new(1.98), {Size = UDim2.new(0.67, 0,0.604,0});

uis.InputBegan:Connect(function(key, proc)
    if proc then return; end
    if key.KeyCode == Enum.KeyCode.E then
        if (workspace.CurrentCamera.CFrame.Position - script.Parent.parent.Position).magnitude > script.Parent.MaxDistance then return; end
        currentTime = tick();
        inside.Visible = true;
        tween:Play();
end)

uis.InputEnded:Connect(function(key, proc)
    if proc then return; end
    if key.KeyCode == Enum.KeyCode.E then
       if math.floor(tick() - CurrentTime) >= 1.99 then
           inside.Visible = false;
           inside.Size = UDUim2.new(0.297, 0, 0.275, 0);
          print("In time");
       else
           tween:Pause()
           print("released at wrong time");
       end
   end
end)

Here’s a more readable block of code with formatting made to be compatible with Roblox’s DevForum’s formatting. Try this one out.

EDIT1: There was a small mistake with tween, forgot to close the bracket/goal with the closing bracket.

2 Likes

Just found out there was no problem with my code, but the script was placed in the workspace so it didn’t work. I will still mark your solution as a solution as it may help others.

Didn’t I post a pic ^^ to show u it doesn’t work in Workspace :smiley:

1 Like