RunService Interference

Hello, I’ve ran into a problem with using RunService, When pressing E the UI stays there instead of playing the UI fade animation. It’s registering the bind press but not doing anything. Why is it doing this?

Clip:

-- Services --
local Players = game:GetService('Players')
local TweenService = game:GetService('TweenService')
local UserInputService = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
-- Variables --
local Player = Players.LocalPlayer
local Character = Player.Character
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
local TweenInteract = TweenInfo.new(0.3,Enum.EasingStyle.Quint,Enum.EasingDirection.Out)
---

-- Functions --
local function GetDistance(Part1,Part2)
	local Vec1 = Vector3.new(Part1.Position.X,0,Part1.Position.Z)
	local Vec2 = Vector3.new(Part2.Position.X,0,Part2.Position.Z)
	return (Vec1 - Vec2).Magnitude
end
---

-- UserInputService --
UserInputService.InputBegan:Connect(function(Input,Busy)
	if Busy then return end
	for OBJ,BillBoard in pairs(workspace:GetDescendants()) do
		if BillBoard:IsA('BillboardGui') and BillBoard.Name == 'Prompt' then
			if Input.KeyCode == Enum.KeyCode.E then
				if GetDistance(HumanoidRootPart,BillBoard.Parent) <= 6 then
					print('E')
					local FrameGoal = {BackgroundTransparency = 1,Size = UDim2.new(0.6,0,0.6,0)}
					local TextGoal = {TextTransparency = 1}
					TweenService:Create(BillBoard.Frame,TweenInteract,FrameGoal):Play()
					TweenService:Create(BillBoard.Frame.Text,TweenInteract,TextGoal):Play()
				end
			end
		end
	end
end)
---

-- RunService --
RunService.RenderStepped:Connect(function(Step)
	-- For Statement --
	for OBJ,BillBoard in pairs(workspace:GetDescendants()) do
		if BillBoard:IsA('BillboardGui') and BillBoard.Name == 'Prompt' then
			if GetDistance(HumanoidRootPart,BillBoard.Parent) <= 6 then
				local FrameGoal = {BackgroundTransparency = 0,Size = UDim2.new(1,0,1,0)}
				local TextGoal = {TextTransparency = 0}
				TweenService:Create(BillBoard.Frame,TweenInteract,FrameGoal):Play()
				TweenService:Create(BillBoard.Frame.Text,TweenInteract,TextGoal):Play()
			else
				local FrameGoal = {BackgroundTransparency = 1,Size = UDim2.new(0.6,0,0.6,0)}
				local TextGoal = {TextTransparency = 1}
				TweenService:Create(BillBoard.Frame,TweenInteract,FrameGoal):Play()
				TweenService:Create(BillBoard.Frame.Text,TweenInteract,TextGoal):Play()
			end
		end
	end
end)
---

-- Main --

---

That was some really loud music.
Please destroy your tweens after you’re done with them. It’s considered a memory leak, and it’s especially bad in this situation. Even worse, you’re creating multiple tweens per RenderStep.
Have you tried using a debounce boolean to check if the player has pressed it, so the RunService doesn’t keep tweening it back in? Use another debounce boolean to also only tween the prompts in once.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.