generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Implementing GetConnectedParts() into this script?

Previous Thread :: Next Thread 
MadSanity is not online. 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 is not online. MadSanity
Joined: 13 Nov 2009
Total Posts: 41506
12 Nov 2017 04:29 PM
Anything?
Report Abuse
MadSanity is not online. MadSanity
Joined: 13 Nov 2009
Total Posts: 41506
12 Nov 2017 05:27 PM
...
Report Abuse
Soybeen is not online. 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 is not online. 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 is not online. 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 is not online. MadSanity
Joined: 13 Nov 2009
Total Posts: 41506
12 Nov 2017 07:10 PM
That worked! Thanks.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image