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

The gui doesn't appear when pressing e?

Asked by
bluzorro 417 Moderation Voter
4 years ago
Edited 4 years ago
-- Local script in starterpack
local debounce = false
local name = "Dave"
local message = "Hey man, what's up?"
local dist = 7

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local interact = game.ReplicatedStorage.Interact

while true do
    for i, npc in pairs(workspace.NPCs:GetChildren()) do
        if (char:WaitForChild("HumanoidRootPart").CFrame.p - npc.HumanoidRootPart.CFrame.p).magnitude <= dist then
            game.ReplicatedStorage.Remotes.StartDialog:FireServer(name, message, npc, dist)     
        end
    end

    wait(1)
end
-- Script inside serverscriptservice
local uis = game:GetService("UserInputService")
local debounce = false
local interact = game.ReplicatedStorage.Interact
local dialog = game.ServerStorage.Dialog

game.ReplicatedStorage.Remotes.StartDialog.OnServerEvent:Connect(function(player, name, message, npc, dist)
    local playerGui = player:WaitForChild("PlayerGui")
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char:WaitForChild("Humanoid")

    if (char:WaitForChild("HumanoidRootPart").CFrame.p - npc.HumanoidRootPart.CFrame.p).magnitude <= dist then
        interact.Parent = playerGui

        uis.InputBegan:Connect(function(input)
            if input.KeyCode == Enum.KeyCode.E and not debounce and interact.Parent == playerGui then
                debounce = true

                print("pressed e")
                dialog.Parent = playerGui
                hum.WalkSpeed = 0
                hum.JumpPower = 0

                wait(1)
                debounce = false
            end
        end)
    else
        interact.Parent = game.ReplicatedStorage
    end
end)

This is my dialog system. The interact gui appears when needed, but the dialog gui doesn't appear when I press e. What can I do to fix this?

3 answers

Log in to vote
1
Answered by 4 years ago

The server is unable to detect input coming from the client. Detecting input must be done from the client for this reason.

If you're going to use a RemoteEvent, then migrate the UserInputService and the actions involving it to the local script, then do what you need to do on the server.

Ad
Log in to vote
0
Answered by
TopBagon 109
4 years ago

ofc it doesn't work cause you're using the "UserInputService" inside a script, tho it can only be used in a local script since it's client-sided...

Log in to vote
0
Answered by
gloveshun 119
4 years ago
Edited 4 years ago

i try to fix it

-- Script inside serverscriptservice
local debounce = false
local interact = game.ReplicatedStorage.Interact
local dialog = game.ServerStorage.Dialog

game.ReplicatedStorage.Remotes.StartDialog.OnServerEvent:Connect(function(player, name, message, npc, dist)
    local playerGui = player:WaitForChild("PlayerGui")
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char:WaitForChild("Humanoid")

    if (char:WaitForChild("HumanoidRootPart").CFrame.p - npc.HumanoidRootPart.CFrame.p).magnitude <= dist then
        interact.Parent = playerGui

        uis.InputBegan:Connect(function(input)
            if input.KeyCode == Enum.KeyCode.E and debounce == false and interact.Parent == PlayerGui then
                debounce = true

                print("pressed e")
                dialog.Parent = PlayerGui
                hum.WalkSpeed = 0
                hum.JumpPower = 0

                wait(1)
                debounce = false
            end
        end)
    else
        interact.Parent = game.ReplicatedStorage
    end
end)

Always watch the capitals, and keep a small space between of lines The Fixed script

-- Script inside serverscriptservice
local debounce = false
local interact = game.ReplicatedStorage.Interact
local dialog = game.ServerStorage.Dialog

game.ReplicatedStorage.Remotes.StartDialog.OnServerEvent:Connect(function(player, name, message, npc, dist)
    local getKeyboard = player:GetMouse()
    local playerGui = player:WaitForChild("PlayerGui")
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char:WaitForChild("Humanoid")

    if (char:WaitForChild("HumanoidRootPart").CFrame.p - npc.HumanoidRootPart.CFrame.p).magnitude <= dist then
        interact.Parent = playerGui

         getKeyboard.KeyDown:Connect(function(input)
            if input == "e" and debounce == false and interact.Parent == playerGui then
                debounce = true

                print("pressed e")
                dialog.Parent = playerGui
                hum.WalkSpeed = 0
                hum.JumpPower = 0

                wait(1)
                debounce = false
            end
        end)
    else
        interact.Parent = game.ReplicatedStorage
    end
end)
0
BRUH... didn't you read what I said above? -.- the "UserInputService" ain't gonna work inside a script it needs to be in a LOCAL SCRIPT! TopBagon 109 — 4y
0
oh, i might can help ya gloveshun 119 — 4y
0
but there was a problem in this script gloveshun 119 — 4y
0
now i made an another script, with your problem fixes gloveshun 119 — 4y

Answer this question