mouse.Target problem

Hello,
I have issue with mouse.Target . I’ve looked at devforum and devhub but found nothing similar with my issue . The issue is the mouse dosent detect anything . Here is the script:

local buses = game.Workspace.Map.Bushes:GetChildren()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local bill = game.StarterGui:WaitForChild("Interract").BushesGrab
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

for i , bushes in pairs(buses) do
		print("hi")
		if mouse.Target.Name == "Leaf" and mouse.Target.Parent == i then
			print("hey")
			if bill.Adornee == nil then
				print("hello")
				bill.Adornee = bushes
				print("aayo")
			end
		else
			bill.Adornee = nil
			print("say wahat")
		end
	end

Any help is appriciated :grinning: . Thank you

The for loop will only run once so I suggest wrapping this into a mouse.Move function like so:

local buses = game.Workspace.Map.Bushes:GetChildren()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local bill = game.StarterGui:WaitForChild("Interract").BushesGrab
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Move:Connect(function()
    for i , bushes in pairs(buses) do
		print("hi")
		if mouse.Target.Name == "Leaf" and mouse.Target.Parent == i then
			print("hey")
			if bill.Adornee == nil then
				print("hello")
				bill.Adornee = bushes
				print("aayo")
			end
		else
			bill.Adornee = nil
			print("say wahat")
		end
	end
end)
1 Like

Would UserInputService be better?

Is it okay if I put RunService.RenderSteppped cuzz when I run the game my fps drop to 6 or less

oops my bad…my gamae just crashed :sweat_smile:

This should help

thanks … I’ll try take a look

I already wattch the vid but I got error . It says

attempt to index nil with 'Parent

everything I dd is same as The Devking do but I got this error . Here is the latest script:

UIS.InputChanged:Connect(function(input)
	
	for i , bushes in pairs(buses) do
		
		if mouse.Target.Parent:IsA("Model") and mouse.Target.Name == bushes.Name then
			bill.Adornee = mouse.Target
			print("aayo")	
		else
			bill.Adornee = nil		
		end
	
	end
end)

Maybe this will work:

local buses = game.Workspace.Map.Bushes:GetChildren()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local bill = game.StarterGui:WaitForChild("Interract").BushesGrab
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

for i, bushes in pairs(buses) do
    print("hi")
    if mouse.Target ~= nil then
        if mouse.Target.Name == "Leaf" and mouse.Target.Parent == i then
        	print("hey")
        	if bill.Adornee == nil then
        		print("hello")
        		bill.Adornee = bushes
        		print("aayo")
        	end
        else
        	bill.Adornee = nil
        	print("say wahat")
        end
    end
end