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

How to cheek that a the part clicked have the name Cartridges?

Asked by 6 years ago

How would you go about to make it only for parts that have the name Cartridges

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local down
local mtarget

function clickObj()
    if mouse.Target ~= nil then
        mtarget = mouse.Target
        print(mtarget)
        down = true
        mouse.TargetFilter = mtarget
        print(mouse.TargetFilter)
    end
end
mouse.Button1Down:connect(clickObj)

function mouseMove()
    if down and mtarget then
        local posX,posY,posZ = mouse.hit.X, mouse.hit.Y, mouse.hit.Z
        mtarget.Position = Vector3.new(posX,posY,posZ)

    end
end

mouse.Move:connect(mouseMove)

function mouseDown()
    down = false
    mouse.TargetFilter = nil

end
mouse.Button1Up:connect(mouseDown)
0
if mouse.Target.Name == "Cartridges" then --code end   -- thank me later piRadians 297 — 6y

1 answer

Log in to vote
0
Answered by
juel90 26
6 years ago
Edited 6 years ago

The Mouse.TargetFilter part was useless you can just do Mouse.Target.Name so your code should now be this.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local down
local mtarget

function clickObj()
    if mouse.Target ~= nil and mouse.Target.Name == "Cartridge" then
        mtarget = mouse.Target.Name
        print(mtarget)
        down = true
    end
end
mouse.Button1Down:connect(clickObj)

function mouseMove()
    if down and mtarget then
        local posX,posY,posZ = mouse.hit.X, mouse.hit.Y, mouse.hit.Z
        mtarget.Position = Vector3.new(posX,posY,posZ)

    end
end

mouse.Move:connect(mouseMove)

function mouseDown()
    down = false
    mtarget = nil
end
mouse.Button1Up:connect(mouseDown)

Ad

Answer this question