MadSanity
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 41506 |
|
|
| 12 Nov 2017 03:42 PM |
bin = script.Parent
function onButton1Down(mouse) local player = game.Workspace:FindFirstChild(script.Parent.Parent.Parent.Name) if player:FindFirstChild("Humanoid") then ________local human = script.Parent.Parent.Parent ________local torso = player.Torso ________local part = (mouse.hit.p) ________local pos1 = torso.Position ________local dist = 10 ________if (pos1 - part).magnitude < dist then ________local PreviousOwner = mouse.Target:FindFirstChild("Owner") if PreviousOwner ~= nil and (?) then ________PreviousOwner:remove() ________local claim = Instance.new("StringValue") ________claim.Name = "Owner" ________claim.Value = human.Name ________claim.Parent = (mouse.Target) elseif PreviousOwner == nil and (?) then ________local claim = Instance.new("StringValue") ________claim.Name = "Owner" ________claim.Value = human.Name ________claim.Parent = (mouse.Target) ________end ________end ________end end
function onSelected(mouse) ________mouse.Button1Down:connect(function() onButton1Down(mouse) end) end
bin.Selected:connect(onSelected)
The conditionals with "(?)" is where I want to check if there are any parts connected to (mouse.Target). My goal is to prevent people from claiming connected parts. IsGrounded was something I wanted to use previously, but it did not account for connected parts that are not connected to something anchored. |
|
|
| Report Abuse |
|
|
MadSanity
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 41506 |
|
| |
|
MadSanity
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 41506 |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 12 Nov 2017 05:38 PM |
There's almost too much wrong with this to go over, but if you manage to properly identify your mouse.Target, to get an array populated with all touching parts, you'd just say
if mouse.Target then local touchingParts = mouse.Target:GetTouchingParts() end |
|
|
| Report Abuse |
|
|
MadSanity
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 41506 |
|
|
| 12 Nov 2017 05:43 PM |
@soy
As far as I'm concerned, this script is working as intended so far, thank you... I guess.
And what you proposed I had already tried, it doesn't seem to work. I don't get any feedback from it either.
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 12 Nov 2017 06:49 PM |
I will go over the little things, because its functional, but.. it's my moral responsibility as a coder to say something XD
local part = (mouse.hit.p) ^ mouse.hit.p is a position (i.e. vector3 value) not a part, also no reason to use parenthesis
local torso = player.Torso ^ you ought to name the variables accordingly, the torso is not a member of the player, it's a member of the character
local PreviousOwner = mouse.Target:FindFirstChild("Owner") ^ assumes there is a mouse.Target, will error if not. Circumvent by checking "if mouse.Target then"
if PreviousOwner ~= nil and (?) then All you need is if PreviousOwner then -- to do thing else -- to not do thing end
PreviousOwner:remove() ^ use :Destroy() instead
As for your issue of determining if there are connected parts, since :GetTouchingParts() returns an array, you'd just check the length of the array
if PreviousOwner and (#mouse.Target:GetTouchingParts() >0 then)
|
|
|
| Report Abuse |
|
|
MadSanity
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 41506 |
|
| |
|