Help with tweening this background

Hi there,

i’m trying to tween the background of a 2D game that i’m currently making. I was using pre-made assets for testing, and was going to add my own original characters after it all works. However, despite there being nothing wrong with the tween code itself, i’m a bit confused as to why it stops working when implemented into the main program.

here is the entirety of the code

local Beep = game.Workspace["Beep!"]

local playerObjection = game.Workspace.playerObjection
playerObjection = false

local oppositionObjection = game.Workspace.oppositionObjection
oppositionObjection = false

local playerTalking = game.StarterGui.Environmen.Characters.Phoenix.Values.IsTalking
local oppositionTalking = game.StarterGui.Environmen.Characters.Phoenix.Values.OpponentTalking

playerTalking = true
oppositionTalking = false

local nameDisplay = game.StarterGui.Text.PlayerText.PlayerName

local playerName = game.Players.LocalPlayer.Name


--THIS IS THE STUFF FOR BACKGROUND!! 



local MainFrameEnvironment = game.StarterGui.Environmen.Characters

local START_POSITION = UDim2.new(0.975, 0, 0.5, 0)

local END_POSITION = UDim2.new(0.05, 0,0.5, 0)

local image = script.Parent.Parent.Objection.ObjectionImage

-- Sound effects
local PEObjection = game.Workspace["OBJECTION! (Phoenix Wright)"]
local MEObjection = game.Workspace["OBJECTION! (Miles Edeworth)"]

local Cornered = game.Workspace["Phoenix Wright - Cornered (Orchestrated)"]
local suspense = game.Workspace["Phoenix Wright Suspense"]


MainFrameEnvironment.Position = START_POSITION

moveToOpposition = function()

	MainFrameEnvironment:TweenPosition(

		END_POSITION,
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		1,
		true

	)
end


local oppositionObject = function()
	
	playerTalking = false
	oppositionTalking = true
	
	
	MEObjection:Play()
	image.ImageTransparency = 0
	image:TweenSize(
		UDim2.new(0.68, 0,  0.54, 0),
		"Out", --direction
		"Linear", --easing style
		.45, -- Duration
		true -- Override any other tweens 
	)

	wait(1.15)
	image.ImageTransparency = 1
	suspense:Stop()
	print("1")
	moveToOpposition()
	print("2")
	Cornered:Play()
end 



-- THIS IS THE STUFF FOR TEXT!!

suspense:Play()


wait(1)

local playerText = {
	
	"Hello",
	"I am here to debate the following topic!",
	"Should developers be allowed to DevEx...",
	"For less?"
	
}


local oppositionText = {
	
	"I believe that to be.. Wrong!",
	"It appears that the defense have left out one major player in this case!",
	"It is an unacceptable gloss-over of this important fact!",
	"What if Roblox don't have enough money to pay out to developers?"
}

local textDisplay = script.Parent

local function typewrite(object, text)
	for i = 1, #text, 1 do
		Beep:Play()
		object.Text = string.sub(text, 1, i)
		wait(0.01)
		Beep:Stop() 
	end
end
--Change the speaker depending on who is talking


while true do

	if playerTalking == true then
		nameDisplay.Text = playerName
		for i, v in pairs(playerText) do
			typewrite(textDisplay, v)
			wait(3)
		end
		oppositionObject()
	elseif playerTalking == false and oppositionTalking == true then
	
		nameDisplay.Text = "Miles Edgeworth"
		for i, v in pairs(oppositionText) do
			typewrite(textDisplay, v)
			wait(3)
		end 

	end
	
end

All this code is situated inside of a textlabel which controls the typing of text (maybe a bad way of handling this, but i’m quite new to scripting)

picture of my workspace is as follows:

the red circle is the script in which all the code is situated

The expected result is down below (done by pasting the code into the command bar)

Hope someone can help!

Are you tweening the players frame or the frame in StarterGui?

Its the frame that’s called ‘Characters’

All the Gui inside of StarterGui gets duplicated into PlayerGui inside the player instance when the player joins, thats how the player sees the gui and only that player. Using StarterGui would just be tweening a gui that noone can see.
I would suggest using script.Parent from the local script as that will define the gui in the player’s playergui
or game.Players.LocalPlayer.PlayerGui

So what exactly would defining the GUI do?

(Sorry if it’s a real simple concept, I’m quite new to this as I’ve said)

It would define the Gui that only the player can see.


as you can see here everything in startergui gets replicated into the player’s playergui. so player2 would only be able to see the gui inside his playergui folder and same with player1, none of the players see whats inside startergui so its useless changing it and player1 can’t see whats in player2’s playergui folder. But the scripts get replicated aswell, so they would work inside the players just at a different time to when they joined.
https://developer.roblox.com/en-us/api-reference/class/StarterGui

If you want the entire server to see the same gui, the easiest way would be to use remote events or functions

This might take a while to learn but hopefully this helped

1 Like

Thanks!

After a bit of reading, i managed to understand where i was doing it wrong, and managed to get it to work!

Thanks again

1 Like