hello,
I have a problem with UserInputService, after pressing “E” nothing happens, but when I press the left mouse button and then “E”, the script works. Why?
Script:
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local UIS = game:GetService("UserInputService")
local GuiActive = false
local PlanetClimed = false
local PlanetSelected
function OnMoved()
if Mouse.Target ~= nil and Mouse.Target.Parent == workspace.Planets then
GuiActive = true
Mouse.Target.InfoGui.Enabled = true
PlanetSelected = Mouse.Target
else
if GuiActive == true then
GuiActive = false
PlanetSelected = nil
for _,v in pairs(workspace.Planets:GetChildren()) do
v.InfoGui.Enabled = false
end
end
end
end
function InputBegan(Input)
if PlanetClimed then return end
if Input.KeyCode == Enum.KeyCode.E and PlanetSelected ~= nil then
PlanetClimed = true
game.ReplicatedStorage.Remote.ClimPlanet:FireServer(PlanetClimed)
end
end
Mouse.Move:Connect(OnMoved)
UIS.InputBegan:Connect(InputBegan)