Hey there, this is a LocalScript in a tool, What this script does is grabs un-anchored Models, (like the move tool) The problem here is, that it picks up Humanoids, is there a way I can put in a function, IF the model contains a Humanoid don't do anything? I am not really sure how to implement this in code form?
Any help please?
local bin = script.Parent local bp = Instance.new("BodyPosition") bp.maxForce=Vector3.new(math.huge, math.huge, math.huge) local movecon = nil local bpfixcon = nil function onchanged(prop, mouse) if bp.Parent ~= nil then if mouse.Hit ~= nil and mouse.Target ~= nil then bp.position=mouse.Hit.p-(mouse.Hit.lookVector*bp.Parent.Size.Y) end end end function onclickdown(mouse) if mouse.Target ~= nil then if mouse.Target.Anchored==false then if bp == nil then bp = Instance.new("BodyPosition") bp.maxForce=Vector3.new(math.huge, math.huge, math.huge)--bp.maxForce*700 bpfixcon:disconnect() bpfixcon = bp.Changed:connect(fixbp) end bp.Parent=mouse.Target bp.position=mouse.Target.Position if bp.Parent.Parent.ClassName~="Model" then mouse.TargetFilter=bp.Parent else mouse.TargetFilter=bp.Parent.Parent end movecon = game:GetService("RunService").Stepped:connect(function(f) onchanged(f, mouse) end) end end end function onclickup(mouse) bp.Parent=nil mouse.TargetFilter=nil if movecon ~= nil then movecon:disconnect() movecon=nil end end function fixbp(prop) if bp == nil then bp = Instance.new("BodyPosition") bp.maxForce=Vector3.new(math.huge, math.huge, math.huge)--bp.maxForce*700 bpfixcon:disconnect() bpfixcon = bp.Changed:connect(fixbp) end end function onselected(mouse) --movecon = game:GetService("RunService").Stepped:connect(function(f) onchanged(f, mouse) end) mouse.Button1Down:connect(function() onclickdown(mouse) end) mouse.Button1Up:connect(function() onclickup(mouse) end) end bin.Selected:connect(onselected)
That is pretty simple, actually. Just check at the onclickdown
function if a FindFirstChild
search in the part's parent returns nil
.
local bin = script.Parent local bp = Instance.new("BodyPosition") bp.maxForce=Vector3.new(math.huge, math.huge, math.huge) local movecon = nil local bpfixcon = nil function onchanged(prop, mouse) if bp.Parent ~= nil then if mouse.Hit ~= nil and mouse.Target ~= nil then bp.position=mouse.Hit.p-(mouse.Hit.lookVector*bp.Parent.Size.Y) end end end function onclickdown(mouse) if mouse.Target ~= nil then if mouse.Target.Parent:FindFirstChild("Humanoid") == nil then --The new if statement, done before everything else must be done. I put it here instead of onchanged so it does not waste time doing things and generally avoid issues and trolling by spamming click on soneone. if mouse.Target.Anchored==false then if bp == nil then bp = Instance.new("BodyPosition") bp.maxForce=Vector3.new(math.huge, math.huge, math.huge)--bp.maxForce*700 bpfixcon:disconnect() bpfixcon = bp.Changed:connect(fixbp) end bp.Parent=mouse.Target bp.position=mouse.Target.Position if bp.Parent.Parent.ClassName~="Model" then mouse.TargetFilter=bp.Parent else mouse.TargetFilter=bp.Parent.Parent end movecon = game:GetService("RunService").Stepped:connect(function(f) onchanged(f, mouse) end) end --New if statement's end end --Your script is exactly the same on this point on end end function onclickup(mouse) bp.Parent=nil mouse.TargetFilter=nil if movecon ~= nil then movecon:disconnect() movecon=nil end end function fixbp(prop) if bp == nil then bp = Instance.new("BodyPosition") bp.maxForce=Vector3.new(math.huge, math.huge, math.huge)--bp.maxForce*700 bpfixcon:disconnect() bpfixcon = bp.Changed:connect(fixbp) end end function onselected(mouse) --movecon = game:GetService("RunService").Stepped:connect(function(f) onchanged(f, mouse) end) mouse.Button1Down:connect(function() onclickdown(mouse) end) mouse.Button1Up:connect(function() onclickup(mouse) end) end bin.Selected:connect(onselected)