MouseEnter/InputBegan not triggering at all

See pictures and code below. I have a frame GuiObject. MouseEnter never triggers. MouseLeave never triggers, InputBegan never triggers. I’m doing something wrong, but I can’t tell what. No errors listed, and no test code ever prints.

All this is supposed to do is switch to walk speed while the mouse is in the center of the screen. No interaction with frame at all should occur.

Things I’ve tried:

  • If the frame is active, I can’t click behind it. Still doesn’t trigger any events.
  • frame “selectable” does nothing.
  • put the script in the StarterGUI folder.
  • run/walk code works in a mouse/moved event using magnitude. Unfortunately, if the camera is zoomed in, it is impossible to run. Thus the need for a gui style approach. There must always be a run and walk zone on screen.
  • Added an imagelabel, visible/invisible, selectable/not selectable (so it’s not just the frame)
  • published game, played from website

image

local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local walkZone = script.Parent

local localPlayer = Players.LocalPlayer
local localCharacter = localPlayer.CharacterAdded:wait()
local humanoid = localCharacter:WaitForChild("Humanoid")
local mouse = localPlayer:GetMouse()
local walkSpeed = 6
local runSpeed = 16

function startWalking ()
    print("Walk detected")
    humanoid.WalkSpeed = walkSpeed
end

function startRunning ()
     print("Run detected")
     humanoid.WalkSpeed = runSpeed
end

walkZone.MouseEnter:Connect(function ()
    startWalking()
end)
walkZone.InputBegan:Connect(startWalking)
walkZone.MouseLeave:Connect(startRunning)

What are you using UserInputService for I see the variable but not where it’s used

1 Like

Great question… I had also considered other methods of interacting with the GUI. That is not currently in use, here.

Are you trying to achieve a function where if you press the GUI, you start sprinting/walking?
Edit: I’m waiting…

1 Like

Change this line:

to this:

local localCharacter = localPlayer.Character or localPlayer.CharacterAdded:wait()
1 Like

Woah… really? Wow… just wow…

Thank you everyone for your help!

Just passing over the gui is the only condition I want. It was a character problem… apparently!