I’ve created my custom NPC chat system and i added some choices to them. The first 1-2 choices are going well but after that the text’s and choice texts kinda get messed up. For an example the choice 2 text is in the choice 3 or reverso.
I tried to solve this by myself, since the necessity is the best teacher but sadly i cannot understand what’s wrong in my script and why are the choices messed up.
Here is the script which includes the tweening, the text changes and so on, controlled by a single button.
local touchSensor = game.Workspace.TouchSensor
local textFrame = game.Players.LocalPlayer.PlayerGui.ShopGuiText.fangisanightmare.TextFrame
local choice1 = game.Players.LocalPlayer.PlayerGui.ShopGuiText.fangisanightmare.Choice1
local choice_1_button = choice1.TextButton
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
local tween = TweenService:Create(camera,
TweenInfo.new(2,
Enum.EasingStyle.Quart,
Enum.EasingDirection.InOut),
{CFrame = game.Workspace.Camera1.CFrame,Focus = game.Workspace.CameraFocus.CFrame})
local function text1()
local text = "Welcome to NINE!"
for i = 1, #text do
textFrame.TextChat.Text = string.sub (text, 1, i)
wait(0.05)
end
end
local function text2()
local text = "Pretty bored. Thinking about some new designs for my Homestore."
for i = 1, #text do
textFrame.TextChat.Text = string.sub(text, 1, i)
wait(0.05)
end
end
local function text3()
local text = "Yeah and i love that! I am actually the creator of the UNTOLD merch."
for i = 1, #text do
textFrame.TextChat.Text = string.sub(text, 1 ,i)
wait(0.05)
end
end
local startDialog = true
local dialog1 = false
local dialog2 = false
local dialog3 = false
local dialog4 = false
local dialog5 = false
game.ReplicatedStorage.OpenGui.OnClientEvent:Connect(function()
if startDialog then --=========================================== start dialog
--//Camera Tweening
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 80
tween:Play()
--//Frame Tween
wait(0.5)
textFrame:TweenPosition(
UDim2.new(0.478, 0,0.615, 0), --End Position
"InOut", --Easing Direction (where the tweeening will happen)
"Quart", --Easing Style
1.3, --Time in seconds
false, --Override other tweens
nil, --Callback (function)
false --Return
)
--// Text animation
wait(0.3)
text1()
--// Choice.1 tweens
wait(0.8)
choice1:TweenPosition( ---0.5, 0,0.748, 0 outside screen
UDim2.new(-0.04, 0,0.748, 0),
"InOut",
"Quart",
1,
false,
nil,
false
)
choice_1_button.MouseEnter:Connect(function()
choice1:TweenSize(
UDim2.new(0.48, 0,0.091, 0),
"InOut",
"Quart",
0.3,
false,
nil,
false
)
end)
choice_1_button.MouseLeave:Connect(function()
choice1:TweenSize(
UDim2.new(0.444, 0,0.091, 0),
"InOut",
"Quart",
0.3,
false,
nil,
false
)
end)
startDialog = false
dialog1 = true
end --=========================================== start dialog
if dialog1 then --=========================================== dialog1
--//Choice1 click
choice_1_button.MouseButton1Click:Connect(function()
--//Choice1 tween back in
choice1:TweenPosition( ---0.5, 0,0.748, 0 outside screen
UDim2.new(-0.5, 0,0.748, 0),
"InOut",
"Quart",
1,
false,
nil,
false
)
text2()
choice_1_button.Text = "You make clothes?"
wait(0.1)
choice1:TweenPosition( ---0.5, 0,0.748, 0 outside screen
UDim2.new(-0.04, 0,0.748, 0),
"InOut",
"Quart",
1,
false,
nil,
false
)
end)
dialog1 = false
dialog2 = true
end --=========================================== dialog1
if dialog2 then --=========================================== dialog2
choice_1_button.MouseButton1Click:Connect(function()
--//Choice1 tween back in
choice1:TweenPosition( ---0.5, 0,0.748, 0 outside screen
UDim2.new(-0.5, 0,0.748, 0),
"InOut",
"Quart",
1,
false,
nil,
false
)
text3()
choice_1_button.Text = "Good job!"
wait(0.1)
choice1:TweenPosition( ---0.5, 0,0.748, 0 outside screen
UDim2.new(-0.04, 0,0.748, 0),
"InOut",
"Quart",
1,
false,
nil,
false
)
end)
dialog2 = false
dialog3 = true
end
end)
Keep in mind that Choice1 is the parent that holds Choice_1_parent. The same button is used throughout the whole script, changing only the text from the TextButton.
Thank you everyone and for more info ask in the replies! ![]()