Does anyone know how I can fix my UI Dialogue System?
-
I’ve hired a scripter to script 3 different UI dialogues for me, the problem is that when you talk to a different npc the camera glitches out.
-
I asked the scripter since he said he would help me if any bugs occured but he blocked me.
-
I already tried my best to try to fix this, but since I didn’t script it and I’m not the best scripter myself I haven’t had any success in fixing it.
-
The problem only seems to occur when talking to the NPC called Joey, and then after it also doesn’t work with the other NPCs
--// Start
local UI = script.Parent
local TS = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local HRP = Char:WaitForChild("HumanoidRootPart")
--// Components
local UpFrame = UI:WaitForChild("UpperFrame")
local LowFrame = UI:WaitForChild("LowerFrame")
local Dialogue = LowFrame:WaitForChild("TextDialogue")
local SkipButton = LowFrame:WaitForChild("SkipDialogue")
local Option = script:WaitForChild("Option")
--// Functions
local function upFrameTween()
local goal = {Position = UDim2.new(0.5,0,0.055,0)}
local info = TweenInfo.new(.25)
UpFrame.Visible = true
local Tween = TS:Create(UpFrame,info,goal)
Tween:Play()
end
local function lowFrameTween()
local goal = {Position = UDim2.new(0.5,0,0.945,0)}
local info = TweenInfo.new(.25)
LowFrame.Visible = true
local Tween = TS:Create(LowFrame,info,goal)
Tween:Play()
end
local function upFrameTweenOut()
local goal = {Position = UDim2.new(0.5,0,-0.25,0)}
local info = TweenInfo.new(.25)
local Tween = TS:Create(UpFrame,info,goal)
Tween:Play()
Tween.Completed:Connect(function()
UpFrame.Visible = false
end)
end
local function lowFrameTweenOut()
local goal = {Position = UDim2.new(0.5,0,1.25,0)}
local info = TweenInfo.new(.25)
local Tween = TS:Create(LowFrame,info,goal)
Tween:Play()
Tween.Completed:Connect(function()
LowFrame.Visible = false
end)
end
local isCameraTweenComplete = false
local function tweenCameraToPart(part)
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local startPosition = camera.CFrame
local endPosition = part.CFrame
local tweenInfo = TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local tween = TS:Create(camera, tweenInfo, {CFrame = endPosition})
tween:Play()
tween.Completed:Connect(function()
isCameraTweenComplete = true
end)
end
local function tweenCameraToStartPosition()
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
end
local function goodOption(button)
button.BorderColor3 = Color3.new(0, 1, 0)
end
local function badOption(button)
button.BorderColor3 = Color3.new(1, 0, 0)
end
--// Prompt
local NPC = game.Workspace:WaitForChild("NPCs"):WaitForChild("Kay")
local Prompt = NPC:WaitForChild("DialoguePrompt"):WaitForChild("ProximityPrompt")
local cams = NPC:WaitForChild("Camera")
local OptionFrame = LowFrame.OptionFrame
local UIList = OptionFrame:WaitForChild('UIListLayout')
local function clearChildExcept(thing)
for _, child in ipairs(OptionFrame:GetChildren()) do
if child.Name ~= thing.Name then
child:Destroy()
end
end
end
local function tweenLighting()
local blur = game.Lighting.Blur
local goal = {Size = 8}
local info = TweenInfo.new(.25)
TS:Create(blur, info, goal):Play()
end
local function tweenLightingOut()
local blur = game.Lighting.Blur
local goal = {Size = 0}
local info = TweenInfo.new(.25)
TS:Create(blur, info, goal):Play()
end
local function anchorPlayer()
HRP.Anchored = true
end
local function unanchorPlayer()
HRP.Anchored = false
end
--// Mute Button Function
local MuteBtn = LowFrame:WaitForChild("MuteBtn")
local muted = false
MuteBtn.MouseButton1Click:Connect(function()
if muted == false then
muted = true
script.SFX.Volume = 0
MuteBtn.Image = script.MuteIcons.MutedImage.Value
elseif muted == true then
muted = false
script.SFX.Volume = 0.5
MuteBtn.Image = script.MuteIcons.UnmutedImage.Value
end
end)
--// Typing Function
local skipClicked = false
local function typing(Dialogue, text)
for i = 1, #text do
if not skipClicked then
Dialogue.Text = string.sub(text, 1, i)
script.SFX:Play()
wait(0.055)
else
Dialogue.Text = text
break
end
end
end
--// Add a function to check the player's distance from the NPC
local function checkPlayerDistance()
local distanceThreshold = 10 -- Set your desired distance threshold here
while true do
local playerPosition = HRP.Position
local npcPosition = NPC.HumanoidRootPart.Position
local distance = (playerPosition - npcPosition).Magnitude
if distance > distanceThreshold then
-- If the player moves away, close the dialogue
Dialogue.Text = ""
tweenCameraToStartPosition()
lowFrameTweenOut()
upFrameTweenOut()
clearChildExcept(UIList)
tweenLightingOut()
Prompt.Enabled = true
end
wait(1) -- Check the distance every second
end
end
--// Skip Mouse Detection
SkipButton.MouseButton1Click:Connect(function()
skipClicked = true
end)
local Active = false
Prompt.TriggerEnded:Connect(function()
spawn(checkPlayerDistance)
isCameraTweenComplete = false
tweenLighting()
upFrameTween()
lowFrameTween()
tweenCameraToPart(cams.Part)
clearChildExcept(UIList)
Dialogue.Text = ""
Prompt.Enabled = false
task.wait(.5)
--// Dialogues
anchorPlayer()
typing(Dialogue, "Hello.", 3, true, 0.05)
wait(1)
unanchorPlayer()
--// Option Handler
local existingOption = OptionFrame:FindFirstChild("NeutralOption")
if existingOption then
clearChildExcept(UIList)
existingOption:Destroy()
end
Dialogue.Text = "Hello."
local NeutralOpt = Option:Clone()
NeutralOpt.Parent = OptionFrame
NeutralOpt.Name = "NeutralOption"
NeutralOpt.Text = "Hello!"
skipClicked = false
NeutralOpt.MouseButton1Click:Connect(function()
clearChildExcept(UIList)
anchorPlayer()
typing(Dialogue, "How are you?", 3, true, 0.05)
wait(1)
unanchorPlayer()
skipClicked = false
Dialogue.Text = "How are you?"
--// Option 1 Handler
local existingOption = OptionFrame:FindFirstChild("Option1")
if existingOption then
existingOption:Destroy()
end
local Option1 = Option:Clone()
Option1.Text = "Good."
Option1.Parent = OptionFrame
Option1.Name = "Option1"
goodOption(Option1)
Option1.MouseButton1Click:Connect(function()
clearChildExcept(UIList)
anchorPlayer()
typing(Dialogue, "That's nice to hear!", 3, true, 0.05)
wait(1)
unanchorPlayer()
local existingOption = OptionFrame:FindFirstChild("LastOption")
if existingOption then
existingOption:Destroy()
end
--// Why?
local FinalOption = Option:Clone()
FinalOption.Parent = OptionFrame
FinalOption.Name = "LastOption"
FinalOption.Text = "Why?"
FinalOption.MouseButton1Click:Connect(function()
clearChildExcept(UIList)
skipClicked = false
anchorPlayer()
typing(Dialogue, "Just asking...", 3, true, 0.05)
wait(1)
unanchorPlayer()
--// Close dialogue function
Dialogue.Text = ""
skipClicked = false
tweenCameraToStartPosition()
lowFrameTweenOut()
upFrameTweenOut()
tweenLightingOut()
Prompt.Enabled = true
end)
end)
--// Option 2 Handler
local existingOption = OptionFrame:FindFirstChild("Option2")
if existingOption then
existingOption:Destroy()
end
local Option2 = Option:Clone()
Option2.Text = "Bad."
Option2.Parent = OptionFrame
Option2.Name = "Option2"
badOption(Option2)
Option2.MouseButton1Click:Connect(function()
clearChildExcept(UIList)
skipClicked = false
anchorPlayer()
typing(Dialogue, "Haha loser", 3, true, 0.05)
wait(1)
unanchorPlayer()
--// Close dialogue function
Dialogue.Text = ""
skipClicked = false
tweenCameraToStartPosition()
lowFrameTweenOut()
tweenLightingOut()
upFrameTweenOut()
Prompt.Enabled = true
end)
end)
end)
local CloseBtn = LowFrame:WaitForChild("ImageButton")
CloseBtn.MouseButton1Click:Connect(function()
Dialogue.Text = ""
tweenCameraToStartPosition()
lowFrameTweenOut()
upFrameTweenOut()
Prompt.Enabled = true
clearChildExcept(UIList)
tweenLightingOut()
end)
If you need me to describe anything specific in the script feel free to ask.
How it normally works
What it does when you talk to a different npc
https://media.discordapp.net/attachments/1233090122417700895/1250520278509813862/image.png?ex=66a49683&is=66a34503&hm=7cc2bbbf19f395bf172ae33d505de34cd7748d52788ad82a435b0ad1bddf3ee6&=&format=webp&quality=lossless&width=1876&height=1056
https://media.discordapp.net/attachments/1233090122417700895/1250520390657376348/image.png?ex=66a4969e&is=66a3451e&hm=f793657d442764f6ca3fb1bbc38fd01f074d63100619d851384331defe0362c9&=&format=webp&quality=lossless&width=1100&height=648
If you need me to describe anything else please feel free to ask.