I am making an FPS game and everything works fine at the moment but I want to add a feature that players drop 1 single model (or part) on death. I have the ammo box whit full scripts in it but I just need to know how to make players drop that part. The ammo box is a part I will change it to a model if that's better
id like information about all the things I need and where to exactly put them in order to do the right thing.
every answer will be appreciated (:
First, insert that ammo box in "Replicated Storage". Now, insert this in a script in StarterPlayer > StarterCharacterScripts:
1 | wait( 5 ) -- waits for the player to load it |
2 |
3 | script.Parent.Humanoid.Died:Connect( function () |
4 | local ClonedAmmoBox = game.ReplicatedStorage:WaitForChild( "WHATEVER YOU NAMED YOUR AMMO BOX" ):Clone() |
5 | ClonedAmmoBox.Parent = game.Workspace |
6 | ClonedAmmoBox.CFrame = CFrame.new(script.Parent:WaitForChild( "HumanoidRootPart" ).Position) |
7 | end ) |
Also, make sure the ammo box is a part and not a model!
What I did is that when the player dies, the script clones the ammo box into the workspace. Then, I set the position of the cloned ammo box at the player's humanoid root part. You could also insert that ammo box in server storage, cuz this is a script and not a local script, but you will have to change the "ReplicatedStorage" at line 4 to "ServerStorage".
use this: (make sure to put it in StarterCharacterScripts) Put the thing you want them to drop in lighting and rename Handle to whatever you need
01 | script.Parent = |
02 | local Torso = script.Parent:FindFirstChild( 'Torso' ) |
03 | function onDied() |
04 | print ( "Script Loaded." ) |
05 | wait( 1 ) |
06 | local n = game.Lighting [ "Handle" ] :Clone() |
07 | n.Parent = game.Workspace |
08 | n.Position = Torso.Position |
09 | n.Handle.Position = script.Parent.Torso.Position |
10 |
11 | end |
12 | while true do |
13 | wait( 0.00000001 ) |
14 | if script.Parent.Humanoid.Health = = 0 then |
15 |
16 | onDied() |
17 | end |
18 |
19 | end |