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)
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.
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.
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”
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)