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

why does this not work? (Mouse problem, specifically target)

Asked by 5 years ago

Local script inside player gui.

local player = game.Players.LocalPlayer
playerMouse = player:GetMouse()
while true do
    wait()
    if playerMouse.Target ~= nil then


        if playerMouse.Target == "BoxOne" then
            print("BoxOne is awesome")
        end

    end
    wait()
end
0
if playerMouse then dont use if playerMouse.Target ~= nil greatneil80 2647 — 5y
0
My guess is that you forgot to actually look for the name property of the target. Try using ' if playerMouse.Target.Name == "BoxOne" then ' instead. saenae 318 — 5y
0
Use local playermouse on the top after local player MaxDev_BE 55 — 5y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

You can use pcall to detect if you are able to get a UserId from the name, as it will error if there is no user with the given name:

local NameTaken = pcall(function()
    return game.Players:GetUserIdFromNameAsync("Name here")
end)
if not NameTaken then
    print("name free")
end
Ad

Answer this question