Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NPC chat using Chat Proximity?

Asked by 2 years ago

I am a new coder and new to lua i was wondering what i would need to add to this code to make the player reply to the npc!

local NPC = script.Parent.Parent.Parent
local TalkEvent = game:GetService("ReplicatedStorage").Npc
local Prox = script.Parent

script.Parent.Triggered:Connect(function(plr)
    plr.Character.Humanoid.WalkSpeed = 0
    plr.Character.Humanoid.JumpHeight = 0
    local NpcName = NPC.Name
    local M1 = script.Parent.Message1.Value
    local M2 = script.Parent.Message2.Value
    local M3 = script.Parent.Message3.Value
    TalkEvent:FireClient(plr,NpcName, M1, M2, M3,Prox)
end)
TalkEvent.OnServerEvent:Connect(function(plr)
    plr.Character.Humanoid.WalkSpeed = 16
    plr.Character.Humanoid.JumpHeight = 7.2
    plr.Character.Humanoid.JumpPower = 50

end)

**This is the script inside the HumanoidRootPart **

local TalkEvent = game:GetService("ReplicatedStorage").Npc

TalkEvent.OnClientEvent:Connect(function(NpcName, M1, M2, M3,Prox)
    Prox.Enabled = false
    script.Parent.Frame.Close.Visible = false
    script.Parent.Frame.Chat.Text = ("...")
    script.Parent.Enabled = true
    script.Parent.Frame.NameTag.Text = NpcName
    task.wait(.2)
    script.Parent.Frame.Chat.Text = M1
    task.wait(2)
    script.Parent.Frame.Chat.Text = M2
    task.wait(2)
    script.Parent.Frame.Chat.Text = M3
    task.wait(2)
    script.Parent.Frame.Close.Visible = true

    script.Parent.Frame.Close.MouseButton1Click:Connect(function()
        script.Parent.Enabled = false
        TalkEvent:FireServer()
        Prox.Enabled = true
    end)
end)

script.Parent.Frame.Close.MouseEnter:Connect(function()
    script.Parent.Frame.Close.Size = UDim2.new(0.394, 0,0.236, 0)
    script.Parent.Frame.Close.Position = UDim2.new(0.303, 0,0.884, 0)

end)
script.Parent.Frame.Close.MouseLeave:Connect(function()
    script.Parent.Frame.Close.Size = UDim2.new(0.342, 0,0.205, 0)
    script.Parent.Frame.Close.Position = UDim2.new(0.329, 0,0.915, 0)
end)

This script is a local script inside chatui which is stored in starter gui

Answer this question