All mouse target scripts broke?

I have a bunch of mouse target scripts and all of them broke, if I can find the issue for one, I can fix the rest, any help? I hope this can be solved.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()
    if mouse.Target and mouse.Target.Name == 'PoogliesDrawer' and (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 then
    game.ReplicatedStorage.PooglieDrawer:FireServer()-- stop code if it isnt false
end
end)

If this is a local script you need to use WaitForChild to get the players character established before continuing.

Hi. Does the output throw any errors?
Also, did those scripts work anytime in the past?

I just tried to put the WaitForChild to no success, any other ideas? And misha, the output doesn’t have any errors (oddly) and the scripts worked in the past yes. Which is why im stumped.

try removing mouse.target and keep mouse.Target.Name

Perhaps add a print so you can see what target the mouse has.

1 Like

Are you sure PoogliesDrawer is a BasePart and no other object is located between that part and the player cam?

Im 100 percent sure, This is because all of my other mouse target scripts don’t work now either, and those ones are outside.

This would cause errors on the client if they clicked on nothing. You would be attempting to get the name of a nil value.
A better solution could be to store the target in a local variable and check if it is nil and then get the name if it is not nil.

1 Like

You can maybe try using pcall to fix it
Not sure though

I just added print statements, it detects the mouse click, but it stops at finding the name and the position of the player and object.

if there is no error output then theres something wrong with these lines:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()

because it’s not going through the function

When I added the print statement, it stopped at the line after that.

after the function or after the if statement?

The if statement. Character30L

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()
	print("clicked")
    if mouse.Target and mouse.Target.Name == 'PoogliesDrawer' and (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 then
	print("mouse target name Poogliesdrawer")
    game.ReplicatedStorage.PooglieDrawer:FireServer()-- stop code if it isnt false
print("fired")
end
end)

this is what i put together, it stops after “clicked”

try this

game.ReplicatedStorage:WaitForChild("PooglieDrawer"):FireServer()

make sure it’s a local script in the starter gui

Try printing mouse.Target to see if it is even detecting the part

The problem must be at the third conditional statement. The magnitude is not in the desired interval. Try writting “Target.Position” instead of “mouse.Hit.p”

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()
	print("clicked")
    if mouse.Target and mouse.Target.Name == 'PoogliesDrawer' then
        if (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 then
	        print("mouse target name Poogliesdrawer")
            game.ReplicatedStorage.PooglieDrawer:FireServer()-- stop code if it isnt false
        print("fired")
    end
end
end)