Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I keep getting an error for a line. Why?

I was just wondering why i keep getting this error when ever i try to run it "Players.Player.PlayerGui.LocalScript:4: attempt to index field 'X' (a number value) 16:29:13.071 - Stack Begin 16:29:13.073 - Script 'Players.Player.PlayerGui.LocalScript', Line 4 16:29:13.074 - Stack End"

local P = game.Players.LocalPlayer
local mouse = P:GetMouse()
local Icon = game.Workspace.Icon:Clone()
	mouse.X.Changed:connect(function()
		
	end)

1 answer

✓ Accepted answer

Integers do not have a Changed event, you have to call that on the PlayerMouse object itself. Additionally, PlayerMouse object have a Move event that only fires when the player moves the mouse:

local P = game.Players.LocalPlayer
local mouse = P:GetMouse()
local Icon = game.Workspace.Icon:Clone()

mouse.Move:connect(function()
	--code
end)

2 comments

1

What good does it do to check if the mouse's x coordinate exists?

0

Nothing, I misread the error in his script. Woops. :P

This discussion is preserved as it was. New answers, comments, and votes are closed.