Press a Button To Respawn a Gear

Hello, so I have a football training game, and when you throw the football the only way to get it back is to grab it or reset. Is there any way to make it so the player presses a button to put a football in their inventory?

Here is what I have so far:


image
image

2 Likes

Edit: I just realized this is to put a ball in inventory, sorry.

Hello, so I have a football training game, and when you throw the football the only way to get it back is to grab it or reset. Is there any way to make it so the player presses a button to put a football in their inventory?
Here is what I have so far:

local football = workspace.Football – path here
local btn = script.Parent

local backup = football:Clone()
backup.Parent = game:GetService(“ReplicatedStorage”)

btn.MouseButton1Click:Connect(function()
if football then
local newball = football:Clone()
newball.Parent = workspace
newball.Name = “Football”
football:Destroy()
else
local newball = backup:Clone()
newball.Parent = workspace
newball.Name = “Football”
end
end)

1 Like
local football = -- ball path
local btn = script.Parent

local p = game.Players.LocalPlayer

btn.MouseButton1Click:Connect(function()
	football:Clone().Parent = p.Backpack
end)

This is a crude script to clone the ball into the player’s backpack.

1 Like

But how do I make it so when I click the button on the screen it duplicates the football and places a new football in the players inv?

The above script is the script that should work. Put it in your gui button. However, make sure to replace the “ball path” with your ball’s path, e.g. game.ReplicatedStorage.Football

The script you provided? or the other persons script?

The problem is, when I throw the football, it clones it to everyone’s inventory.

A:

To give a player an item you can use this code:
– player is the player that should get the item
– item is the item object

player.Backpack:AddItem(item)

The script I provided.

characters

image

:AddItem does not work on Backpack.

Local is underlined. Does this matter?

You should replace --ball path with your ball’s location in your game.

Replacing --ball path with your ball’s location should remove the error.

The balls location??? What is that?

For example, game.ReplicatedStorage.Football, or wherever your ball tool is in game.

I don’t have anything in replicated storage for the button

I realize that. Could you please send a picture of where your tool is located? Possibly in ServerStorage or StarterPack?

I want it so the player does not spawn with the football, but once they click the button it gives them a football. They can throw it and press the button to get another one.

The football is located under startpack.