Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I stop TweenService from making the frame "YEET" off my screen?

My script is detecting loud audio and then moves a frame over but it keeps flying off the screen how can i prevent this? gif -- it yeeting off the screen gui positions -- the location of the gui

if sound.PlaybackLoudness >=400 then
	game.ReplicatedStorage.TooLoud:FireServer(plr)
	plr.PlayerGui.Radio.UI.loud.move.Visible = true
	plr.PlayerGui.Radio.UI.loud.move:TweenPosition(UDim2.new(5, 0.5,0, 0),"Out","Bounce",2,true)
	wait(5)
	plr.PlayerGui.Radio.UI.loud.move:TweenPosition(UDim2.new(5, 0.5,0, 0),"In","Bounce",2,true)
	wait(2)
	plr.PlayerGui.Radio.UI.loud.move.Visible = false
end
end)

1 comment

0

im going to make it Instance.new a frame later

1 answer

✓ Accepted answer

GENERAL PRACTICE

The "Out / In" and "Bounce" are Enum Properties, so a String will work sometimes, but not for all players.

ISSUES

The TweenPosition (UDim2.new(5, 0.5,0, 0)) moves the frame 5 times its current placement on the x-axis plus an additional 0.5 pixel offset, which based on the size of your frame, would move it out of the picture.

Secondly, You used TweenPosition for the same exact location, so the frame would not move to a new location after the first tween.

Based on comments in the chat, you can set the position to the below coordinates for it to move to the near center of the screen. If you check the frame's original position as a local variable you can preset where it will move back to.

I cannot see what the connection of your function is or where the local sound is, so you will have to update these from the below script.

Revised Local Script

local plr = game:GetService("Players").LocalPlayer
local sound = script:WaitForChild("Sound")
local ui = plr:WaitForChild("PlayerGui"):WaitForChild("Radio"):WaitForChild("UI"):WaitForChild("loud"):WaitForChild("move")
local position = ui.Position

script.Parent.Activated:Connect(function()
	if sound.PlaybackLoudness >= 400 then
		game:GetService("ReplicatedStorage"):WaitForChild("TooLoud"):FireServer(plr)
		ui.Visible = true
		ui:TweenPosition(UDim2.new(0.083, 0, 0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Bounce, 2, true)
		wait(5)
		ui:TweenPosition(position, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 2, true)
		wait(2)
		ui.Visible = false
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.