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: y no work

Previous Thread :: Next Thread 
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 06:15 PM
This doesn't work. I have a hat named "Space hat" and when the clickDetector is clicked it still kills me. There are no errors. Here is the script:

script.Parent.ClickDetector.MouseClick:connect(function(touch)
for i,v in pairs(game.Players:GetChildren()) do
for a,q in pairs(v.Character:GetChildren()) do
if q:IsA("Hat") then
if q.Name == "Space Hat" then
print("nop")
else
v.Character:BreakJoints()
end
end
end
end
end)
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 06:21 PM
boomp
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 06:22 PM
It's killing you because it also found parts that aren't a Hat. You need kill the player only after the loop through their parts completes and comes up with no Space Hat.

        script.Parent.ClickDetector.MouseClick:connect(function(touch)
                for i, v in pairs(game.Players:getChildren()) do
                        safe = false
                        for a, q in pairs(v.Character:getChildren()) do
                                if (q:isA("Hat") and q.Name == "Space Hat") then
                                        safe = true
                                        break
                                end
                        end
                        if (not safe) then v.Character:BreakJoints() end
                end
        end

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 06:23 PM
Oh, thanks.
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 06:25 PM
Sure thing. :3

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 06:29 PM
What's 'break' do? I've never used/seen it before.
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 06:34 PM
"break" is a fairly universal programming feature that just "breaks" out of the current loop. Some programming languages allow to write "break 3" or similar terms, which breaks out of three current levels of looping, defaulting to 1 if not specified.

It just saves computing time; it's a major part of pruning, if you're familiar with the term in a programming context.

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 06:44 PM
Also, one more thing, I'm making a button that shuts off oxygen. Anyone without the helmet dies. I tried adding some loops like:
while ox==false do
safe=false
end

and

while (not safe) do
v.Character:BreakJoints()
wait(5)
end

to the script, but it's not working. How would I make the oxygen off when clicked once, then the second click it's back on?
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:05 PM
This should do what you're asking for. :3

        vacuumEvents = {}       

        function onClick(touch)
                if (#vacuumEvents == 0) then
                        for i, player in pairs(game.Players:getChildren()) do
                                vacuumEvents[#vacuumEvents] = player.CharacterAdded:connect(checkHelmet)
                                checkHelmet(player.Character)
                        end
                else
                        for i, event in pairs(vacuumEvents) do
                                event:disconnect()
                        end
                end
        end

        function checkHelmet(char)
                helmet = char:findFirstChild("Space Hat")
                if (helmet == nil or not helmet:isA("Hat")) then
                        char:BreakJoints()
                else
                        vacuumEvents[#vacuumEvents] = helmet.AncestryChanged:connect(helmetMoved)
                end
        end
        
        function helmetMoved(helmet, parent)
                if (helmet.Parent:findFirstChild("Humanoid") == nil) then
                        for i, player in pairs(game.Players:getChildren()) do
                                checkHelmet(player.Character)
                        end
                end
        end

        script.Parent.ClickDetector.MouseClick:connect(onClick)

The first function toggles the atmosphere.
The second function handles people who have no helmets.
The third function handles people who took off their helmets without an atmosphere.

————
Smile.
        Know fun.
                Live life.
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:08 PM
Correction:

        for i, event in pairs(vacuumEvents) do
                event:disconnect()
        end
        vacuumEvents = {} -- Add this line!

Sorry.

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:11 PM
Thank you so much!
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:13 PM
Any time. ;3

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:19 PM
Hope I don't sound greedy, eh, but how would I make it keep killing all the "no-helmeters" until oxygen is toggled back on by someone clicking the button?
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:24 PM
Nothing greedy about it at all. :3

The code above should already do that. It connects the checkHelmet function to everybody through the CharacterAdded event, then removes the event when the room is repressurized.

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:33 PM
It doesn't seem to do it. I click it, it kills me, I respawn (no helmet upon respawn), and it does not continue the killing.
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:37 PM
Huh. That's odd, because the part that creates the event comes *before* it kills you.

Maybe the second function needs a delay on it. Try adding

        wait(3)

to checkHelmet()'s first line.

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:38 PM
vacuumEvents[#vacuumEvents] = player.CharacterAdded:connect(checkHelmet)
--here?
checkHelmet(player.Character)
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:41 PM
Sorry. Like this, in the second function:

        function checkHelmet(char)
                wait(3)
                --[[ ... ]]
        end

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:44 PM
That part works now, but there is no way to enable oxygen again. Or, at least, it doesn't work.
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:46 PM
RBLX Lua's specifications are off. Apparently CharacterAdded *still* doesn't wait to fire until after the model is loaded completely. Bah.

Alright; repressurizing:
Did you catch my correction? Because that should fix it if you hadn't.

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:49 PM
I added that, maybe it's in the wrong spot..? I'll post everything I have so far.

vacuumEvents = {}

function onClick(touch)
if (#vacuumEvents == 0) then
for i, player in pairs(game.Players:getChildren()) do
vacuumEvents[#vacuumEvents] = player.CharacterAdded:connect(checkHelmet)
checkHelmet(player.Character)
end
else
for i, event in pairs(vacuumEvents) do
event:disconnect()
end
vacuumEvents = {}
end
end

function checkHelmet(char)
wait(3)
helmet = char:findFirstChild("Space Hat")
if (helmet == nil or not helmet:isA("Hat")) then
char:BreakJoints()
else
vacuumEvents[#vacuumEvents] = helmet.AncestryChanged:connect(helmetMoved)
end
end

function helmetMoved(helmet, parent)
if (helmet.Parent:findFirstChild("Humanoid") == nil) then
for i, player in pairs(game.Players:getChildren()) do
checkHelmet(player.Character)
end
end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 07:53 PM
Mind publishing your place so I can see what's happening? I can't find anything wrong with the code just looking at it, and if you're not getting any errors, I'm not sure what to do except to explore the problem a bit.

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 07:58 PM
Sure, shall I invite you to a party?
Report Abuse
TheArmyHasHonor is not online. TheArmyHasHonor
Joined: 16 Jul 2008
Total Posts: 544
09 Jan 2014 08:00 PM
If you'd like. :3

————
Smile.
        Know fun.
                Live life.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
09 Jan 2014 08:01 PM
Okay.
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