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

This way of detecting if mouse.Hit got changed doesn't work, how do i fix it?

I don't mind changing the way i do it, i just need something that works

--- there is a lot more to the script above this
local mouse = player:GetMouse()
local mh = mouse.Hit

	ev:FireServer(mh)
	
local currentmh = mh

mouse:GetPropertyChangedSignal("Hit"):Connect(function()
	
	if(mh ~= currentmh)then
		
		mh = mouse.Hit
		
		currentmh = mh
	
	 print("hit changed")
   

	
	wait()
	ev2:FireServer(mh)
	end
	
	end)

3 comments

0

are you sure you dont need the mouse position?

0

are you sure you dont need the mouse position?

0

guess the position can work too

1 answer

GetPropertyChangedSignal was disabled for Hit because it'd update way too often, IIRC.

You can try and use a loop in RenderStepped to check for it, specifically after user input (Priority 100)

--NOTE: untested
local mouse = game:GetService"Players".LocalPlayer:GetMouse()
local mh = mouse.Hit
ev:FireServer(mh)
local currentmh = mh
game:GetService"RunService":BindToRenderStep("MHUpdate",Enum.RenderPriority.Input.Value + 1,function()
	mh=mouse.Hit
	if(mh ~= currentmh)then
	    mh = mouse.Hit
	    currentmh = mh
		print("hit changed")
		wait()
		ev2:FireServer(mh)
	end
end)

See the articles below for some more info.

https://developer.roblox.com/en-us/api-reference/function/RunService/BindToRenderStep

https://developer.roblox.com/en-us/api-reference/function/RunService/UnbindFromRenderStep

https://developer.roblox.com/en-us/api-reference/event/RunService/RenderStepped

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