Tweens not playing in Custom Proximity Prompt Script

Hey Developers,

So I watched a youtube tutorial and scripted a Custom Proximity Prompt script, however the tweens appear to be not working. They work in the video however. The video is here. This is the script:

local ProximityPromptService = game:GetService("ProximityPromptService")
local Player = game.Players.LocalPlayer

local PlayerGui = Player:WaitForChild("PlayerGui")
local CustomPrompt = script:WaitForChild("Prompt")

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local GamepadButtonImage = {
	[Enum.KeyCode.ButtonX] = "rbxasset://textures/ui/Controls/xboxX.png",
	[Enum.KeyCode.ButtonY] = "rbxasset://textures/ui/Controls/xboxY.png",
	[Enum.KeyCode.ButtonA] = "rbxasset://textures/ui/Controls/xboxA.png",
	[Enum.KeyCode.ButtonB] = "rbxasset://textures/ui/Controls/xboxB.png",
	[Enum.KeyCode.DPadLeft] = "rbxasset://textures/ui/Controls/dpadLeft.png",
	[Enum.KeyCode.DPadRight] = "rbxasset://textures/ui/Controls/dpadRight.png",
	[Enum.KeyCode.DPadUp] = "rbxasset://textures/ui/Controls/dpadUp.png",
	[Enum.KeyCode.DPadDown] = "rbxasset://textures/ui/Controls/dpadDown.png",
	[Enum.KeyCode.ButtonSelect] = "rbxasset://textures/ui/Controls/xboxmenu.png",
	[Enum.KeyCode.ButtonL1] = "rbxasset://textures/ui/Controls/xboxLS.png",
	[Enum.KeyCode.ButtonR1] = "rbxasset://textures/ui/Controls/xboxRS.png",
}

local KeyboardButtonImage = {
	[Enum.KeyCode.Backspace] = "rbxasset://textures/ui/Controls/backspace.png",
	[Enum.KeyCode.Return] = "rbxasset://textures/ui/Controls/return.png",
	[Enum.KeyCode.LeftShift] = "rbxasset://textures/ui/Controls/shift.png",
	[Enum.KeyCode.RightShift] = "rbxasset://textures/ui/Controls/shift.png",
	[Enum.KeyCode.Tab] = "rbxasset://textures/ui/Controls/tab.png",
}

local KeyboardButtonIconMapping = {
	["'"] = "rbxasset://textures/ui/Controls/apostrophe.png",
	[","] = "rbxasset://textures/ui/Controls/comma.png",
	["`"] = "rbxasset://textures/ui/Controls/graveaccent.png",
	["."] = "rbxasset://textures/ui/Controls/period.png",
	[" "] = "rbxasset://textures/ui/Controls/spacebar.png",
}

local KeyCodeToTextMapping = {
	[Enum.KeyCode.LeftControl] = "Ctrl",
	[Enum.KeyCode.RightControl] = "Ctrl",
	[Enum.KeyCode.LeftAlt] = "Alt",
	[Enum.KeyCode.RightAlt] = "Alt",
	[Enum.KeyCode.F1] = "F1",
	[Enum.KeyCode.F2] = "F2",
	[Enum.KeyCode.F3] = "F3",
	[Enum.KeyCode.F4] = "F4",
	[Enum.KeyCode.F5] = "F5",
	[Enum.KeyCode.F6] = "F6",
	[Enum.KeyCode.F7] = "F7",
	[Enum.KeyCode.F8] = "F8",
	[Enum.KeyCode.F9] = "F9",
	[Enum.KeyCode.F10] = "F10",
	[Enum.KeyCode.F11] = "F11",
	[Enum.KeyCode.F12] = "F12",
}

local function GetScreenGui()
	
	local ScreenGui = PlayerGui:FindFirstChild("ProximityPrompts")
	
	if ScreenGui == nil then
		
		ScreenGui = Instance.new("ScreenGui")
		
		ScreenGui.Name = "ProximityPrompts"
		ScreenGui.ResetOnSpawn = false
		
		ScreenGui.Parent = PlayerGui
		
	end
	
	return ScreenGui
	
end

local function CreatePrompt(Prompt, InputType, GUI)
	
	local PromptUI = CustomPrompt:Clone()
	
	local Frame = script.Prompt.Frame
	local ActionText = Frame.ActionText
	
	local ObjectText = Frame.ObjectText
	local ButtonText = Frame.InputFrame.Frame.ButtonText
	
	local ButtonImage = Frame.InputFrame.Frame.ButtonImage
	local TextTable = {ActionText, ButtonText, ObjectText}
	
	local function UpdateUIFromPrompt()
		
		ActionText.Text = Prompt.ActionText
		ObjectText.Text = Prompt.ObjectText
		
		if InputType == Enum.ProximityPromptInputType.Gamepad then
			
			if GamepadButtonImage[Prompt.GamepadKeyCode] then
				
				ButtonImage.Image = GamepadButtonImage[Prompt.GamepadKeyCode]
				
			end
			
		elseif InputType == Enum.ProximityPromptInputType.Touch then
			
			ButtonImage.Image = "rbxasset://textures/ui/Controls/TouchTapIcon.png"
			
		else
			
			ButtonImage.Image = "rbxasset://textures/ui/Controls/key_single.png"
			
			local ButtonTextString = UserInputService:GetStringForKeyCode(Prompt.KeyboardKeyCode)
			local ButtonTextImage = KeyboardButtonImage[Prompt.KeyboardKeyCode]
			
			if ButtonTextImage == nil then
				
				ButtonTextImage = KeyboardButtonIconMapping[ButtonTextString]
				
			end
			
			if ButtonTextImage == nil then
				
				local KeyCodeMappedText = KeyCodeToTextMapping[Prompt.KeyboardKeyCode]
				
				if KeyCodeMappedText then
					
					ButtonTextString = KeyCodeMappedText
					
				end
				
			end
			
			if ButtonTextImage then
				
				ButtonImage.Image = ButtonTextImage
				
			elseif ButtonTextString ~= nil and ButtonTextString ~= '' then
				ButtonText.Text = ButtonTextString
			else
				error("ProximityPrompt '" .. Prompt.Name .. "' has an unsupported keycode for rendering UI: " .. tostring(Prompt.KeyboardKeyCode))
			end
			
		end
		
	end
	
	UpdateUIFromPrompt()
	
	local TweensForFadeOut = {}
	local TweensForFadeIn = {}
	local TweenInfoFast = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
	
	for _, Object in ipairs(TextTable) do
		
		table.insert(TweensForFadeOut, TweenService:Create(Object, TweenInfoFast, { TextTransparency = 1 }))
		table.insert(TweensForFadeIn, TweenService:Create(Object, TweenInfoFast, { TextTransparency = 0 }))
		
	end
	
	table.insert(TweensForFadeOut, TweenService:Create(Frame, TweenInfoFast, { Size = UDim2.fromScale(0, 1), BackgroundTransparency = 1, Visible = false }))
	table.insert(TweensForFadeIn, TweenService:Create(Frame, TweenInfoFast, { Size = UDim2.fromScale(1,1), BackgroundTransparency = 0.5, Visible = true }))
	
	if InputType == Enum.ProximityPromptInputType.Touch or Prompt.ClickablePrompt then
		
		local Button = Instance.new("TextButton")
		
		Button.BackgroundTransparency = 1
		Button.TextTransparency  = 1
		
		Button.Size = UDim2.fromScale(1,1)
		Button.Parent = PromptUI
		
		local ButtonDown = false
		
		Button.InputBegan:Connect(function(Input)
			
			if (Input.UserInputType == Enum.UserInputType.Touch or Input.UserInputType == Enum.UserInputType.MouseButton1) and
				Input.UserInputState ~= Enum.UserInputState.Change then
				
				Prompt:InputHoldBegin()
				
				ButtonDown = true
				
			end
			
		end)
		
		Button.InputEnded:Connect(function(Input)
			
			if Input.UserInputType == Enum.UserInputType.Touch or Input.UserInputType == Enum.UserInputType.MouseButton1 then
				
				if ButtonDown then
					
					ButtonDown = false
					Prompt:InputHoldEnd()
					
				end
				
			end
			
		end)
		
		PromptUI.Active = true
		
	end
	
	local TriggeredConnection
	local TriggerEndedConnection
	
	TriggeredConnection = Prompt.Triggered:Connect(function()
		
		for _, Tween in ipairs(TweensForFadeOut) do
			
			Tween:Play()
			
		end
		
	end)
	
	TriggerEndedConnection = Prompt.TriggerEnded:Connect(function()
		
		for _, Tween in ipairs(TweensForFadeIn) do
			
			Tween:Play()
			
		end
		
	end)
	
	PromptUI.Adornee = Prompt.Parent
	PromptUI.Parent = GUI
	
	for _, Tween in ipairs(TweensForFadeIn) do
		
		Tween:Play()
		
	end
	
	local function CleanupFunction()
		
		TriggeredConnection:Disconnect()
		TriggerEndedConnection:Disconnect()
		
		for _, Tween in ipairs(TweensForFadeIn) do

			Tween:Play()

		end
		
		wait(0.2)
		
		PromptUI.Parent = nil
		
	end
	
	return CleanupFunction

end

ProximityPromptService.PromptShown:Connect(function(Prompt, InputType)
	
	if Prompt.Style == Enum.ProximityPromptStyle.Default then
		
		return
		
	end
	
	local GUI = GetScreenGui()
	
	local CleanupFunction = CreatePrompt(Prompt, InputType, GUI)
	
	Prompt.PromptHidden:Wait()
	
	CleanupFunction()
	
end)

tweens are located near the bottom. How do I fix the tween not working?

A bit late to this, but has nothing shown up in output?

1 Like

Nothing has shown up in the output :frowning:

Through testing, it appears that you’re tweening the original prompt thats in the script instead of the cloned version.

So how do I fix it? Im confused

The variables in the tweens are set to change the original objects. You just need to set the variables to instead change the cloned objects.

I dont think so.



image

The first picture doesnt tell me anything because of the way its cropped.
The second picture proves my point; the variables are being set for the prompt that’s in the script instead of the stuff inside of PromptUI, the clone.

Im still confused. Perhaps this would be easier through discord.

Dom.#6274

Might as well explain here if the question arises to anyone else.

Here are your variables:

local PromptUI = CustomPrompt:Clone() --cloned version of the Prompt Billboard Gui

local Frame = script.Prompt.Frame --the premade Prompt Gui stored in the script
local ActionText = Frame.ActionText 

local ObjectText = Frame.ObjectText
local ButtonText = Frame.InputFrame.Frame.ButtonText

local ButtonImage = Frame.InputFrame.Frame.ButtonImage

Everything below the Frame variable is a child of “Frame”. Since “Frame” is part of the original prompt, the variables that are children of “Frame” are part of the original prompt as well.

When you create the tweens…

table.insert(TweensForFadeOut, TweenService:Create(Frame, TweenInfoFast, { Size = UDim2.fromScale(1,1), BackgroundTransparency = 0.5, Visible = true }))

…you’re referring to the frame of the original Prompt, which doesn’t leave the script. What you want to be doing instead when creating the tweens is referring to the cloned version of the Prompt’s parts since that’s what gets parented to the part with the ProximityPrompt object.

A basic way to do this is to just make/set your variable to the required objects after cloning the whole prompt gui, then create your tween when that’s done, having it set to the cloned variables.
Example:

local clonedPrompt = Prompt:Clone()
local thingToTween = clonedPrompt.thing

tweenServ:Create(thingToTween, tweenInfo, {tweenProperties} --refers to the CLONED object inside the CLONED gui
1 Like