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!