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: Giving players their gear back after they spawn

Previous Thread :: Next Thread 
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
04 Jan 2012 04:13 PM
Okay, so in my game, players can pick up tons and tons of gear. Then when they die, I would like to give them EXACTLY what they had before they died.

My first approach was to connect to the Humanoid's Died event, and then I would know exactly which gear he had. The problem is that by the time I get the message usually the backpack has been cleared.

I also tried using .HealthChanged if the health was 0, and this fired sooner, but not soon enough.

So now I have tried to do something like this:
1. When the script first runs, make a table indexed with all the gear in the player's backpack AND in his character (i.e. that he has equipped)

2. connect to Character.ChildRemoved and if the gear is now in the Workspace, he must've backspaced it. Remove it from the to-save list.

3. connect to Character.ChildAdded and if I've never seen the gear before, he must've just picked it off the ground. Add to the save list.

The problem is that gear are removed from the backpack sometimes BEFORE the humanoid's health is even zero. So how do I know who is clearing the backpack?

Augh!!!!
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
04 Jan 2012 04:15 PM
Why don't you just clone the gear into the player's StarterPack, which is cloned into the Backpack when they respawn?
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
04 Jan 2012 04:17 PM
I did that but then most gear would inexplicably break.

The way my system works is by identifying the gear, getting the appropiate AssetId, and then re-inserting the gear using LoadAsset when the player respawns.
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
04 Jan 2012 04:22 PM
When you say that sometimes the gear is mysteriously removed, I believe there's a certain gear or two that hides the weapons for a certain duration and then parents them back, so you should probably also connect the ChildAdded/Removing events to the backpack.
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
04 Jan 2012 04:37 PM
Add a script into every tool you have that clones it into the player's StarterGear when it's equipped. It should look like this:

    script.Parent.Equipped:connect(function(mouseObject)
        local parentClone = script.Parent:Clone()
        local playerObject = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
        if playerObject then
            parentClone.Parent = playerObject.StarterGear
        end
    end)

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
04 Jan 2012 04:38 PM
I don't know if it's StarterGear or StarterPack, sorry. Make the necessary changes.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
04 Jan 2012 04:40 PM
Why not just make a global table for each player, and when they die, clone all the tools and insert it into the table... Then when they spawn, clone their tools back into there backpack.

×Dyslexic Scripter at Work×
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
04 Jan 2012 04:40 PM
Oh, fixed:

    script.Parent.Equipped:connect(function(mouseObject)
        local parentClone = script.Parent:Clone()
        local playerObject = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
        if playerObject then
            if not playerObject.StarterPack:FindFirstChild(parentClone) then
                parentClone.Parent = playerObject.StarterPack
            end
        end
    end)

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
04 Jan 2012 04:41 PM
@Other suggestions

Sorry but that's a horrible mess to figure out, sometimes gear break when they are cloned, or there might be a duplicate gear, etc.

One problem I'm having is that when you backspace a gear, it doesn't go right into the Workspace. It is actually parented to nil. :/ How do I know the difference other than a wait statement?
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