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