I'm trying to tween size of a custom proximityprompt button

Hello for 2 hours, I have been trying to tween a text button which is located in a billboard, and I made sure that the gui was connected with the proximityprompt

Currently the function to enlarge the button when using mouseEnter… works perfectly,

But I would like to add in addition, when the player uses the Keycode “E” then that play the tween size for the button,

I’ll let you analyze my script, I’ve already tried a lot of different ways, I recently added a task.wait() although it’s not the best way, nothing works.

There is probably a misuse of something, please help me.

local PromptGui = script.Parent
local ActionText = PromptGui.TextLabel
local Button = PromptGui.Button
local TS = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

PromptGui.Enabled = false

local function enlargeButton()
	local tweenGrow = TS:Create(Button, TweenInfo.new(0.2), {Size = UDim2.new(0.4, 0, 0.8, 0)})
	tweenGrow:Play()
	warn("Button enlarged")
end

local function shrinkButton()
	local tweenShrink = TS:Create(Button, TweenInfo.new(0.2), {Size = UDim2.new(0.35, 0, 0.7, 0)})
	tweenShrink:Play()
	warn("Button shrunk")
end

function SetupProximityPrompt(ProximityPrompt)
	ProximityPrompt.HoldDuration = 0

	ProximityPrompt.PromptShown:Connect(function()
		PromptGui.Enabled = true
		PromptGui.Adornee = ProximityPrompt.Parent
		ActionText.Text = ProximityPrompt.ActionText
		Button.Text = ProximityPrompt.KeyboardKeyCode
		warn("Prompt shown")
	end)

	ProximityPrompt.PromptHidden:Connect(function()
		PromptGui.Enabled = false
		PromptGui.Adornee = nil
		warn("Prompt hidden")
	end)

	ProximityPrompt.Triggered:Connect(function(inputObject)
		if inputObject.KeyCode == Enum.KeyCode.E then
			warn("ProximityPrompt triggered")
			enlargeButton()
			task.wait(0.1)
			shrinkButton()
		end
	end)
end

for i, v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("ProximityPrompt") then
		SetupProximityPrompt(v)
	end
end

game.Workspace.DescendantAdded:Connect(function(Child)
	if Child:IsA("ProximityPrompt") then
		SetupProximityPrompt(Child)
	end
end)

Button.MouseEnter:Connect(function()
	enlargeButton()
	warn("Mouse entered button")
end)

Button.MouseLeave:Connect(function()
	shrinkButton()
	warn("Mouse left button")
end)

Patch : you can use without the task.wait*
but i prefer, for a simple game

local PromptGui = script.Parent
local ActionText = PromptGui.TextLabel
local Button = PromptGui.Button
local TS = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

PromptGui.Enabled = false

local function enlargeButton()
	if Button.Size ~= UDim2.new(0.4, 0, 0.8, 0) then
		TS:Create(Button, TweenInfo.new(0.2), {Size = UDim2.new(0.4, 0, 0.8, 0)}):Play()
		warn("Button enlarged")
	end
end

local function shrinkButton()
	if Button.Size ~= UDim2.new(0.35, 0, 0.7, 0) then
		TS:Create(Button, TweenInfo.new(0.2), {Size = UDim2.new(0.35, 0, 0.7, 0)}):Play()
		warn("Button shrunk")
	end
end

function SetupProximityPrompt(ProximityPrompt)
	ProximityPrompt.HoldDuration = 0

	ProximityPrompt.PromptShown:Connect(function()
		PromptGui.Enabled = true
		PromptGui.Adornee = ProximityPrompt.Parent
		ActionText.Text = ProximityPrompt.ActionText
		Button.Text = ProximityPrompt.KeyboardKeyCode
		warn("Prompt shown")
	end)

	ProximityPrompt.PromptHidden:Connect(function()
		PromptGui.Enabled = false
		PromptGui.Adornee = nil
		warn("Prompt hidden")
	end)
end

for _, v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("ProximityPrompt") then
		SetupProximityPrompt(v)
	end
end

game.Workspace.DescendantAdded:Connect(function(Child)
	if Child:IsA("ProximityPrompt") then
		SetupProximityPrompt(Child)
	end
end)

Button.MouseEnter:Connect(function()
	enlargeButton()
	warn("Mouse entered button")
end)

Button.MouseLeave:Connect(function()
	shrinkButton()
	warn("Mouse left button")
end)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if PromptGui.Enabled then
			enlargeButton()
			task.wait(0.15)
			shrinkButton()
		end
	end
end)

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