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

How do I fix the press e to chat?

Asked by 5 years ago

key bind script (in starter gui, with image button, (in image button there is uiaspectratioconstraint, local script, and two text labels)) key bind is in local script:

local UIS = game:GetService("UserInputService") -- Service used to get the key pressed by a player
UIS.InputBegan:connect(function(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then -- Checks if the player uses a Keyboard
        if input.KeyCode == Enum.KeyCode.E then -- Checks if the player pressed the "E" key
            if UIS:GetFocusedTextBox() == nil then -- Checks if the player is typing on a textbox like the chat... If not then...
                for i,v in pairs(game.Workspace.NPCS:GetChildren()) do -- Finds all the children from the folder. In this case it will find all the NPCs
                    local mag = (v.Torso.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
                    if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then
                        --Effect XD
                        for i = 1,0.6,-0.05 do
                            wait()
                            script.Parent.ImageColor3 = Color3.new(i,i,i)
                        end
                        wait()
                        for i = 0.6,1,0.05 do
                            wait()
                            script.Parent.ImageColor3 = Color3.new(i,i,i)
                        end
                        --This effect is like when you pressed a button it will darken.
                        v.NPCTalk:FireServer()
                    end
                end
            end
        end
    end
end)

while wait() do
    script.Parent.Visible = false -- Makes it invisible on screen
    for i,v in pairs(game.Workspace.NPCs:GetChildren()) do -- Finds all the children from the folder. In this case it will find all the NPCs
        local mag = (v.Torso.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
        if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then
            local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(v.Torso.Position) -- The position of the NPC's Torso to 2d
            script.Parent.Visible = true
            script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
            script.Parent.TextLabel.Text = "to chat with "..v.Name -- Refreshes the text and puts the name of the npc
        end
    end
end

in dummy in gui, in textbutton

script.Parent.NPCTalk.OnServerEvent:connect(function(player)
    if not player.PlayerGui:FindFirstChild("") then -- Checks if the player already has the gui. Put your gui name between the quotation marks to the name of your GUI
        local gui = script.Parent:FindFirstChild(""):Clone() -- Change here too. Clones the gui
        gui.Parent = player.PlayerGui -- Clone the gui and put its parent to the player gui.
    end
end)

0
Which part of it isn't working? royaltoe 5144 — 5y
0
All of it, the key bind, the image popping up when close to npc that says press e to interact, and the screen gui that pops up when pressing e RamenRobloxian 2 — 5y
0
The keypress seems when I tested it in game. Nothing is wrong with the magnitude logic. Your fade transition seems to work logically. Your gui is going to be flickering on and off though because you have a loop turning it on and off if the player is a certain distance away. Your event looks like it should fire fine, but " " does not seem like a valid gui name. change that to your actual gui name. royaltoe 5144 — 5y
0
Do you mind if I have a copy of it so I can test it myself / invite me to team create? royaltoe 5144 — 5y
View all comments (5 more)
0
Sorry I do not trust anybody RamenRobloxian 2 — 5y
0
But if you could share a game with me, I could paste the dummy and all scripts into it RamenRobloxian 2 — 5y
0
ye that would work royaltoe 5144 — 5y
0
whats your username royaltoe 5144 — 5y
0
i added you - i'm royaltoe royaltoe 5144 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(input,gameProcessed)
        if input.KeyCode == Enum.KeyCode.E then
                for i,v in pairs(game.Workspace.NPCS:GetChildren()) do
                    local mag = (v.Torso.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
                    if mag <= 10 then
                        for i = 1,0.6,-0.05 do
                            wait()
                            script.Parent.ImageColor3 = Color3.new(i,i,i)
                        end
                        wait()
                        for i = 0.6,1,0.05 do
                            wait()
                            script.Parent.ImageColor3 = Color3.new(i,i,i)
                        end
                        v.NPCTalk:FireServer()
                   end
             end
       end
end)

--[[here is your error, running a white wait() do loop will never let the other parts in the script run
while wait() do
    script.Parent.Visible = false -- Makes it invisible on screen
    for i,v in pairs(game.Workspace.NPCs:GetChildren()) do -- Finds all the children from the folder. In this case it will find all the NPCs
        local mag = (v.Torso.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
        if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then
            local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(v.Torso.Position) -- The position of the NPC's Torso to 2d
            script.Parent.Visible = true
            script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
            script.Parent.TextLabel.Text = "to chat with "..v.Name -- Refreshes the text and puts the name of the npc
        end
    end
end]]

you dont need to check if the user is typing on the keyboard, all u need to check is what letter is being used. you dont need to check if the player is talking in chat either since that automaticaly disables the input code from running

0
sorry it does not work RamenRobloxian 2 — 5y
Ad

Answer this question