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 » Scripting Helpers
Home Search
 

Re: Lock on touch

Previous Thread :: Next Thread 
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:18 PM
I made a script for an object that locks things that come in contact with it... however, it dosen't lock anything. There's also a print command which works fine; this tells me that it's recognizing the collision. Here's the code:

function onTouched(hit)
hit.Locked = true
print 'Locked Part!'
end
script.Parent.Touched:connect(onTouched)

Whats wrong?
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:23 PM
Bump

Report Abuse
madness725 is not online. madness725
Joined: 19 Apr 2011
Total Posts: 2058
16 Oct 2013 09:31 PM
Try defining the part with

part = script.Parent

I think with "hit" you are locking the part that touches the brick. Or is that what your trying to do?
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:33 PM
yea, I want it to lock parts that touch it.

Oh, and it's moving down with a TranslateBy command... does that screw up the collision detection?
Report Abuse
Oozlebachr is not online. Oozlebachr
Joined: 30 Aug 2009
Total Posts: 22223
16 Oct 2013 09:35 PM
does translateby use cframe

cframe doesn't really cooperate with touched very well iirc
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:38 PM
Well, I hafta use c-framing (TranslateBy in this case). If I don't, the part will get stuck on everything and it won't lock your creations.
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:44 PM
bump
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
16 Oct 2013 09:48 PM
I think you're confusing 'Locked' and 'Anchored'. Locked determines whether or not the Part can be selected by Studio tools, Anchored determines whether or not it is effected by physics.
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:50 PM
Okay, maybe I should explain to you what I need. I'm making a building game. In each building area, given to each player, there will be a button. Pressing this button causes an invisible and canCollide false brick to dash through the room, locking anything in it's path. The object uses the TranslateBy command to move down -2 studs pere 0.01 seconds and it returns to its original position in 10 seconds.
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:51 PM
*to move down 2 seconds
*per 0.01 seconds

I hate typos... ._.
Report Abuse
Ekkoh is not online. Ekkoh
Joined: 22 Oct 2012
Total Posts: 524
16 Oct 2013 09:53 PM
Why not just loop through the model and lock everything...

"To sing when you live and to sing when you die" - George Ragan
Report Abuse
Oozlebachr is not online. Oozlebachr
Joined: 30 Aug 2009
Total Posts: 22223
16 Oct 2013 09:55 PM
use this function

function lock(t)
for i,v in ipairs(t:GetChildren()) do
pcall(function() v.Locked = true end)
lock(v)
end
end
Report Abuse
Ekkoh is not online. Ekkoh
Joined: 22 Oct 2012
Total Posts: 524
16 Oct 2013 09:57 PM
Or better yet

local function lock(model)
for _, obj in pairs(model:GetChildren()) do
if obj:IsA("BasePart") then
obj.Locked = true
end
lock(obj)
end
end

"To sing when you live and to sing when you die" - George Ragan
Report Abuse
Oozlebachr is not online. Oozlebachr
Joined: 30 Aug 2009
Total Posts: 22223
16 Oct 2013 09:57 PM
actually wait that would take a little bit more work to implement in your place
use findpartsinregion3 to get all of the parts inside the building area then lock them
http://wiki.roblox.com/index.php/FindPartsInRegion3_(Method)
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 09:58 PM
I have no knowledge in functions... do I replace the old lock script with this, or do I sandwich it between the onTouched command?
Report Abuse
Ekkoh is not online. Ekkoh
Joined: 22 Oct 2012
Total Posts: 524
16 Oct 2013 09:58 PM
Or if he parented all copied parts to a model for each user with a custom copy tool it would make things a whole lot easier.

"To sing when you live and to sing when you die" - George Ragan
Report Abuse
Oozlebachr is not online. Oozlebachr
Joined: 30 Aug 2009
Total Posts: 22223
16 Oct 2013 09:59 PM
@ekkoh yeah but im going to assume he doesn't want to do extra work for that
Report Abuse
Ekkoh is not online. Ekkoh
Joined: 22 Oct 2012
Total Posts: 524
16 Oct 2013 10:00 PM
@tinarg I'd try to find a different way before you resort to that. Trust me, that's the last method you'd wanna use to accomplish this.

"To sing when you live and to sing when you die" - George Ragan
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 10:00 PM
No fancy region stuff... I need this code to work with 6 different bases, all in different locations. What is the easiest way I can do this effectively? and I have no clue what half the stuff your talking about is... :\
Report Abuse
Ekkoh is not online. Ekkoh
Joined: 22 Oct 2012
Total Posts: 524
16 Oct 2013 10:03 PM
If I were you I'd find a decent scripter who is willing to help you with your game, it's going to be the easiest if they have a copy of your game so they can see the layout of everything and determine what the best way is.

"To sing when you live and to sing when you die" - George Ragan
Report Abuse
Oozlebachr is not online. Oozlebachr
Joined: 30 Aug 2009
Total Posts: 22223
16 Oct 2013 10:03 PM
the easiest way is a combination of the lock function and ekkoh's idea of using a modified copy tool
you would have the copy tool parent everything to a model assigned to a player then evoke the lock function by typing lock(the location of the model storing the parts)

there's not really an easy easy way to do it but yeah
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 10:04 PM
But this is the only problem I have... I'm just asking what I put in place for the lock on touch script.
Report Abuse
Ekkoh is not online. Ekkoh
Joined: 22 Oct 2012
Total Posts: 524
16 Oct 2013 10:06 PM
@tinarg BRUH, scrap the "on touch" script. That idea is not going to produce the results you want. I'll fix something up for you for a price if you're interested, but I'm not going to waste my time just so you can make more money and credits for yourself.

"To sing when you live and to sing when you die" - George Ragan
Report Abuse
tinarg is online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
16 Oct 2013 10:09 PM
*Sigh* I'm not trying to be one of those people, even if it looks like it. I'll just go dissect some random model and see what that does.
Report Abuse
Oozlebachr is not online. Oozlebachr
Joined: 30 Aug 2009
Total Posts: 22223
16 Oct 2013 10:10 PM
tinarg you could use bodyvelocity or bodyposition to move the brick instead of translating it with cframe so the touched event would work

not very efficient but it should work decently if the brick is moving slowly
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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