-- 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?
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.
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...
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)