Need someone To help me with a mouseposition script

Hi guys, I was tryna make a hold to work button in a game, It was done by clickdetectors before but clickdetector doesnt detect mousebutton hold. So I used Userinput service and it works and gets the mouse position from the local script but How Do I know that the player is pointing at that exact button that needs to work and not just get in the way of the other buttons which are close to eachother.
Here’s my script:

remote.OnServerEvent:Connect(function(player,mousepos,state)
	if state == true then
		print("working")
		model:SetPrimaryPartCFrame(part.CFrame + (part.CFrame.LookVector*speed.Value))
			sound:Play()
			switch.BrickColor = BrickColor.new("Bright green")
			switch.Position = Vector3.new(42.703, 3.688, -251.86) 
			tweenplay1:Play()
			tweenplaypropel1:Play()
			task.wait(0.3)
			task.wait(1)
			watersound:Play()
		if working == false then
			print("notworking")
			tweenplay2:Play()
			sound:Play()
			tweenplaypropel2:Play()
			switch.BrickColor = BrickColor.new("Dark stone grey")
			switch.Position = Vector3.new(42.703, 3.788, -251.86)
			task.wait(0.3)
			task.wait(0.7)
		end
		end
end)

Would mouse.Target solve your issue?

Oh yeah, Mouse.Target returns the Part where the mousecursor of the player is pointing if im not mistaken. Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.