Can’t really explain this, but I have a Subtitle script I made and when the player touches (not really touches, I use magnitude) or “falls down” to a point, a Subtitle is supposed to appear.
Problem is, all 3 subtitles appear at once, any fix?
Touch Script (Server-side)
local RS = game:GetService("ReplicatedStorage")
local Events = RS:WaitForChild("Events")
local FellEvent = Events:WaitForChild("Fell")
local fell = 0
local db = false
local Player
local Character
local Magnitude
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
Player = plr
Character = char
end)
end)
while task.wait() do
if Character then
Magnitude = (script.Parent.Position - Character.PrimaryPart.Position).Magnitude
if Magnitude < 35 then
if db == true then return end
Character:SetPrimaryPartCFrame(workspace.Part1.Teleport.CFrame)
FellEvent:FireClient(Player, fell)
fell += 1
task.wait(0.5)
db = false
end
end
end
Subtitle Script
--[[ NOCHIT
AddSubtitle() -- Adds a ubtitle
FadeIn:Play() -- Tweens the Subtitle's Transparency
]]
-- Events
local RS = game:GetService("ReplicatedStorage")
local Events = RS:WaitForChild("Events")
local PlayEvent = Events:WaitForChild("Play")
local FellEvent = Events:WaitForChild("Fell")
local KeyPoint = Events:WaitForChild("keypoint")
-- Player
local Player = game:GetService("Players").LocalPlayer
local PlayerUI = Player.PlayerGui
local SubtitleScript = script:WaitForChild("Script")
-- Tweening
local TS = game:GetService("TweenService")
local FadeInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0)
local FadeInGoal = {}
FadeInGoal.TextTransparency = 0
function AddSubtitle(Text)
-- "text" is the text to subtitle
-- Set UI
local UI = Instance.new("ScreenGui"); UI.Parent = PlayerUI
local Frame = Instance.new("Frame"); Frame.Parent = UI
local Subtitle = Instance.new("TextLabel"); Subtitle.Parent = Frame
UI.Name = "Subtitle"
Subtitle.Name = "Subtitle"
-- Fade Text
local FadeIn = TS:Create(Subtitle, FadeInfo, FadeInGoal)
-- Frame
Frame.Size = UDim2.new(0.5, 0, 0.1, 0)
Frame.Position = UDim2.new(0.25, 0, 0.75, 0)
Frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
Frame.BackgroundTransparency = 1
Frame.BorderSizePixel = 0
-- Subtitle
-- Looks
Subtitle.Position = UDim2.new(0, 0, 0, 0)
Subtitle.Size = UDim2.new(1, 0, 1, 0)
Subtitle.TextTransparency = 1
Subtitle.Font = Enum.Font.Roboto
Subtitle.TextSize = 1
Subtitle.RichText = true
Subtitle.TextScaled = true
Subtitle.BorderSizePixel = 0
--Colors
Subtitle.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
Subtitle.TextColor3 = Color3.fromRGB(255, 255, 255)
-- Transparency
Subtitle.BackgroundTransparency = 1
Subtitle.TextStrokeTransparency = 1
-- Set Text
SubtitleScript:Clone().Parent = UI
FadeIn:Play()
Subtitle.Text = "<b>".. Text .."</b>"
function AddSFX(id)
local SFX = Instance.new("Sound")
SFX.Parent = UI
SFX.SoundId = "rbxassetid://".. id
SFX.Volume = 0.1
SFX:Play()
end
end
-- Player started the game.
PlayEvent.Event:Connect(function()
AddSubtitle("Well hello, ".. Player.Name .." and welcome to my game. So, this is a little project I've been working on and I hope you'll like it..")
AddSFX(12478957378)
task.wait(10)
KeyPoint:Fire()
AddSubtitle("I'm uh, not really a talkative person.. Alright so look um in that side or the other side, I think you're facing the right way, just walk over to that door and enter it.. I should've marked it, and uh, let's start")
task.wait(13)
KeyPoint:Fire()
workspace.BarrierModel:Destroy()
end)
-- Player fell down in part1
FellEvent.OnClientEvent:Connect(function()
AddSubtitle("Hey buddy, be careful!")
end)
local db = false
FellEvent.OnClientEvent:Connect(function(interrupted)
if db == true then return end
db = true
if interrupted == 0 then
KeyPoint:Fire()
task.wait()
AddSubtitle("Would you let me finish my sentence atleast?")
elseif interrupted == 1 then
KeyPoint:Fire()
task.wait()
AddSubtitle("Listen you need to be careful!")
elseif interrupted == 2 then
KeyPoint:Fire()
task.wait()
AddSubtitle("FOR GOD'S SAKE LET ME FINISH.")
end
print(interrupted)
task.wait(0.5)
db = false
end)
EDIT: Yeah uh I had an extra AddSubtitle() somewhere in my script, sorry.
Finished script:
--[[ NOCHIT
AddSubtitle() -- Adds a ubtitle
FadeIn:Play() -- Tweens the Subtitle's Transparency
]]
-- Events
local RS = game:GetService("ReplicatedStorage")
local Events = RS:WaitForChild("Events")
local PlayEvent = Events:WaitForChild("Play")
local FellEvent = Events:WaitForChild("Fell")
local KeyPoint = Events:WaitForChild("keypoint")
-- Player
local Player = game:GetService("Players").LocalPlayer
local PlayerUI = Player.PlayerGui
local SubtitleScript = script:WaitForChild("Script")
-- Tweening
local TS = game:GetService("TweenService")
local FadeInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0)
local FadeInGoal = {}
FadeInGoal.TextTransparency = 0
function AddSubtitle(Text)
-- "text" is the text to subtitle
-- Set UI
local UI = Instance.new("ScreenGui"); UI.Parent = PlayerUI
local Frame = Instance.new("Frame"); Frame.Parent = UI
local Subtitle = Instance.new("TextLabel"); Subtitle.Parent = Frame
UI.Name = "Subtitle"
Subtitle.Name = "Subtitle"
-- Fade Text
local FadeIn = TS:Create(Subtitle, FadeInfo, FadeInGoal)
-- Frame
Frame.Size = UDim2.new(0.5, 0, 0.1, 0)
Frame.Position = UDim2.new(0.25, 0, 0.75, 0)
Frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
Frame.BackgroundTransparency = 1
Frame.BorderSizePixel = 0
-- Subtitle
-- Looks
Subtitle.Position = UDim2.new(0, 0, 0, 0)
Subtitle.Size = UDim2.new(1, 0, 1, 0)
Subtitle.TextTransparency = 1
Subtitle.Font = Enum.Font.Roboto
Subtitle.TextSize = 1
Subtitle.RichText = true
Subtitle.TextScaled = true
Subtitle.BorderSizePixel = 0
--Colors
Subtitle.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
Subtitle.TextColor3 = Color3.fromRGB(255, 255, 255)
-- Transparency
Subtitle.BackgroundTransparency = 1
Subtitle.TextStrokeTransparency = 1
-- Set Text
SubtitleScript:Clone().Parent = UI
FadeIn:Play()
Subtitle.Text = "<b>".. Text .."</b>"
function AddSFX(id)
local SFX = Instance.new("Sound")
SFX.Parent = UI
SFX.SoundId = "rbxassetid://".. id
SFX.Volume = 0.1
SFX:Play()
end
end
-- Player started the game.
PlayEvent.Event:Connect(function()
AddSubtitle("Well hello, ".. Player.Name .." and welcome to my game. So, this is a little project I've been working on and I hope you'll like it..")
AddSFX(12478957378)
task.wait(10)
KeyPoint:Fire()
AddSubtitle("I'm uh, not really a talkative person.. Alright so look um in that side or the other side, I think you're facing the right way, just walk over to that door and enter it.. I should've marked it, and uh, let's start")
task.wait(13)
KeyPoint:Fire()
workspace.BarrierModel:Destroy()
end)
local db = false
FellEvent.OnClientEvent:Connect(function(interrupted)
if db == true then return end
db = true
if interrupted == 0 then
KeyPoint:Fire()
task.wait()
AddSubtitle("Would you let me finish my sentence atleast?")
elseif interrupted == 1 then
KeyPoint:Fire()
task.wait()
AddSubtitle("Listen you need to be careful!")
elseif interrupted == 2 then
KeyPoint:Fire()
task.wait()
AddSubtitle("FOR GOD'S SAKE LET ME FINISH.")
end
print(interrupted)
task.wait(0.5)
db = false
end)