Hey there!
I’m having difficulties with a script intended to close a frame when the player moves, which prevents them from interacting with the frame from a distance, resulting in it being abused. The script itself works, however returns the following error every step the player takes, regardless of whether or not the frame is open.
Players.DishwasherSushi.PlayerGui.BusTicketGui.CloseOnMoveScript:7: attempt to index nil with ‘Visible’
I have searched through similar posts, however I have yet to find one that relates to my issue and resolves it using the solutions marked on said posts. Below you can find all relevant information.
Pathway
Code
local player = game.Players.LocalPlayer
local frame = script.Parent
local function onPlayerMove()
if frame.Visible == true then
frame.Visible = false
end
end
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection.Magnitude > 0 then
onPlayerMove()
end
end)```