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

How to play a sound effect when the npc talk with you?

Asked by 4 years ago
Edited 4 years ago

Hello, i am trying to make a sound play when a npc talk with you. But i can't, any suggestion?

Script:

local UIS = game:GetService("UserInputService")

local Template = script.Parent:WaitForChild("Template")
local E = script.Parent.Parent:WaitForChild("EThing"):WaitForChild("E")

local Player = game:GetService("Players").LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")

local VarHolder
local Text
local CurrentTrigger
local NPC
local db
local abletochange = true
local StoredValues = {}
local function DisableMove()
    if(Character.Humanoid.WalkSpeed~=0)then
        StoredValues = {Character.Humanoid.WalkSpeed,Character.Humanoid.JumpPower}
        Character.Humanoid.WalkSpeed = 0
        Character.Humanoid.JumpPower = 0
    end
end

local function EnableMove()
    Character.Humanoid.WalkSpeed = StoredValues[1]
    Character.Humanoid.JumpPower = StoredValues[2]
end

RootPart.Touched:Connect(function(otherPart)
    if(otherPart.Name=="TriggerBlock3")then
        CurrentTrigger = otherPart.NPCTitle.Value
        E.Visible = true
        E.Parent.Adornee = otherPart
        NPC = otherPart.Parent.NPC
    end
end)

RootPart.TouchEnded:Connect(function(otherPart)
    if(otherPart.Name=="TriggerBlock3")then
        CurrentTrigger = nil
        E.Visible = false
        E.Parent.Adornee = nil
        NPC = nil
    end
end)

UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent)
    if(inputObject.KeyCode==Enum.KeyCode.E)and(not(db))then
        if(CurrentTrigger)then
            SetNewNpc()
        end
    end
end)

wait (0)
script.Sound:Play()

function SetNewNpc()
    if(abletochange)then
        VarHolder = NPC.Parent.TriggerBlock3
        TextValue = VarHolder.Text
        Text = TextValue.Value
        SetNewTextBox()
    end
end

function SetNewTextBox()
    if(not(db))then
        db = true
        DisableMove()
        local TextBox = Template:Clone()
                TextBox.Parent = script.Parent
                TextBox.Text = ""
                TextBox.Size = UDim2.new(0,500,0,100)
                TextBox.Position = UDim2.new(0.5,-250,1,-150)
                TextBox.Visible = true
        for i=1,string.len(Text) do
            TextBox.Text = string.sub(Text, 1, i)
            wait(0.02)
        end
        UIS.InputBegan:Wait()
        TextBox:Destroy()
        if(TextValue:FindFirstChildOfClass("StringValue"))then
            VarHolder = TextValue
            TextValue = VarHolder.Text
            Text = TextValue.Value
            abletochange = false
            db = false
            SetNewTextBox()
        else
            EnableMove()
            wait(1)
            db = false
            abletochange = true
        end
    end
end
0
Instance.new("Sound",player) or something. Idk if you want everyone to hear the sound then just put it in workspace or put it somewhere on the player otherwise. voidofdeathfire 148 — 4y
0
It's just a npc talking, only the guy who is talking with the npc... SamuelGames_YTx -3 — 4y

Answer this question