this code.
-- Server Script
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local dialogueEvent = ReplicatedStorage:FindFirstChild("DialogueEvent") or Instance.new("RemoteEvent", ReplicatedStorage)
dialogueEvent.Name = "DialogueEvent"
local choiceEvent = ReplicatedStorage:FindFirstChild("ChoiceEvent") or Instance.new("RemoteEvent", ReplicatedStorage)
choiceEvent.Name = "ChoiceEvent"
local soundFolder = SoundService:FindFirstChild("CutsceneSounds") or Instance.new("Folder", SoundService)
soundFolder.Name = "CutsceneSounds"
local function playSound(id, vol, pit)
local s = Instance.new("Sound")
s.SoundId = id
s.Volume = vol
s.Pitch = pit
s.Parent = soundFolder
s:Play()
Debris:AddItem(s, 2)
end
local Dialogues = {
{ text="Oh hey uhh...", textSpeed=0.125, delayBeforeNext=1 },
{
text="Ig im here for testing",
textSpeed=0.065,
delayBeforeNext=1,
choices={
{ text="Mirror Man?", nextIndex=3 },
{ text="End chat", nextIndex=5 },
{ text="Replay intro", nextIndex=1 },
},
},
{
text="I'm Metal Man, not Mirror Man.",
textSpeed=0.075,
delayBeforeNext=2,
choices={
{ text="Oh.", nextIndex=4 },
},
},
{
text="Wanna test more?",
textSpeed=0.0575,
delayBeforeNext=1,
choices={
{ text="Yes", nextIndex=2 },
{ text="No", nextIndex=5 },
{ text="Loop question", nextIndex=4 },
},
},
{ text="Alright, bye!", textSpeed=0.1, delayBeforeNext=0.5 },
}
local triggered = {}
local clickPart = script.Parent
local detector = clickPart:FindFirstChildOfClass("ClickDetector") or Instance.new("ClickDetector", clickPart)
detector.MouseClick:Connect(function(player)
if triggered[player] then return end
triggered[player] = true
spawn(function()
dialogueEvent:FireClient(player, "start")
local idx = 1
while Dialogues[idx] do
local d = Dialogues[idx]
playSound("rbxassetid://129600471584011", 1, 0.925)
task.wait(0.35)
for i = 1, #d.text do
dialogueEvent:FireClient(player, "updateText", d.text:sub(1, i))
playSound("rbxassetid://129600471584011", 0.65, 1.5)
task.wait(d.textSpeed)
end
task.wait(d.delayBeforeNext)
if d.choices then
dialogueEvent:FireClient(player, "choices", d.choices)
local choice, conn
conn = choiceEvent.OnServerEvent:Connect(function(p, sel)
if p == player then
choice = sel
conn:Disconnect()
end
end)
repeat task.wait() until choice
dialogueEvent:FireClient(player, "clear") -- clear after choice
idx = d.choices[choice].nextIndex
else
dialogueEvent:FireClient(player, "clear")
idx = idx + 1
end
end
dialogueEvent:FireClient(player, "end")
triggered[player] = nil
end)
end)
make it that if it is a humanoid then make it look at the player with 8 directions.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local p = Players.LocalPlayer
local function setupMovement(char)
local h = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
h.AutoRotate = false
RunService.RenderStepped:Connect(function()
local d = h.MoveDirection
if d.Magnitude > 0 then
local a = math.atan2(d.X, d.Z)
local step = math.pi/4
a = math.floor(a/step + 0.5) * step
local dir = Vector3.new(math.sin(a), 0, math.cos(a))
hrp.CFrame = CFrame.new(hrp.Position, hrp.Position + dir)
h:Move(dir, false)
end
end)
end
if p.Character then setupMovement(p.Character) end
p.CharacterAdded:Connect(setupMovement)
-- Local Script
local player = game.Players.LocalPlayer
local gui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui"))
gui.Name = "DialogueUI"
gui.Enabled = false
local box = Instance.new("TextLabel", gui)
box.Size = UDim2.new(0.6,0,0.15,0)
box.Position = UDim2.new(0.2,0,0.8,0)
box.BackgroundColor3 = Color3.new(0,0,0)
box.BackgroundTransparency = 0.25
box.TextColor3 = Color3.new(1,1,1)
box.TextScaled = true
box.Font = Enum.Font.SourceSansBold
local choiceBG = Instance.new("Frame", gui)
choiceBG.Size = UDim2.new(0.6,0,0,0)
choiceBG.Position = UDim2.new(0.2,0,0.75,0)
choiceBG.BackgroundColor3 = Color3.new(0,0,0)
choiceBG.BackgroundTransparency = 0.25
choiceBG.Visible = false
local choiceFrame = Instance.new("Frame", choiceBG)
choiceFrame.Size = UDim2.new(1,0,1,0)
choiceFrame.Position = UDim2.new(0,0,0,0)
choiceFrame.BackgroundTransparency = 1
local function clearChoices()
for _, c in ipairs(choiceFrame:GetChildren()) do
if c:IsA("TextButton") then c:Destroy() end
end
choiceBG.Visible = false
choiceBG.Size = UDim2.new(0.6,0,0,0)
end
local function showChoices(choices)
clearChoices()
local count = #choices
local height = 30
choiceBG.Size = UDim2.new(0.6,0,0, height+8)
choiceBG.Visible = true
for i, opt in ipairs(choices) do
local btn = Instance.new("TextButton", choiceFrame)
btn.Size = UDim2.new(1/count, -4, 0, height)
btn.Position = UDim2.new((i-1)/count, 2, 0, 4)
btn.BackgroundTransparency = 1
btn.BorderSizePixel = 1
btn.BorderColor3 = Color3.new(1,1,1)
btn.TextColor3 = Color3.new(1,1,1)
btn.TextScaled = true
btn.Font = Enum.Font.SourceSans
btn.Text = opt.text
btn.MouseButton1Click:Connect(function()
clearChoices()
game.ReplicatedStorage:WaitForChild("ChoiceEvent"):FireServer(i)
end)
end
end
game.ReplicatedStorage:WaitForChild("DialogueEvent").OnClientEvent:Connect(function(cmd, data)
if cmd=="start" then
gui.Enabled = true
elseif cmd=="updateText" then
box.Text = data
elseif cmd=="choices" then
showChoices(data)
elseif cmd=="clear" then
box.Text = ""
elseif cmd=="end" then
gui.Enabled = false
clearChoices()
end
end)