Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Issues with Mouse.Target, help?

Asked by
yurhomi10 192
10 years ago

when I click the baseplate, it just prints the name of the brick but won't print "ITS BASE" but when I click a non object(nil) it prints "LOL NAAA"..

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Down:connect(function(click)
    print(mouse.Target)

    if mouse.Target == "BasePlate" then
        print("ITS BASE!")
    elseif mouse.Target == nil then
        print("LOL NAAA")
    end
end)

2 answers

Log in to vote
6
Answered by 10 years ago
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Down:connect(function(click)
    print(mouse.Target)

    if mouse.Target and mouse.Target.Name == "BasePlate" then --Check if the name of the target is BasePlate
        print("ITS BASE!")
    elseif mouse.Target == nil then
        print("LOL NAAA")
    end
end)
0
Wow, Thanks, I did mouse.Target.Name == "BasePlate" then - but it didnt work and was giving me this weird error. Thanks again bud! yurhomi10 192 — 10y
1
Because if Mouse.Target is nil it would error. Articulating 1335 — 10y
Ad
Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
10 years ago

You forgot to check its name You were just checking if the object was a BasePlate.

player = game.Players.LocalPlayer
mouse = player:GetMouse()
mouse.Button1Down:connect(function(click)
    if mouse.Target~=nil then --Check to make sure it wont break
        if mouse.Target.Name == "BasePlate" then --Needs to check its name
            print("ITS BASE!")
        elseif mouse.Target == nil then
            print("LOL NAAA")
        end
    end 
end)

Answer this question