Help with starter gear

I’m trying to make a script that permanently gives a player a specific tool. I’m assuming that I have to put the tool in the player’s starter gear, but it doesn’t work. The cloned tool is found in the player’s stater gear, but it doesn’t give the tool to the player if the player resets.

local button = script.Parent.TextButton

local tool = game.ReplicatedStorage.ClassicSword

local player = game.Players.LocalPlayer

button.MouseButton1Up:Connect(function()

local ClonedTool = tool:Clone()

ClonedTool.Parent = player.Backpack

local ClonedToool = tool:Clone()

ClonedToool.Parent = player.StarterGear

end)
1 Like

I’m pretty sure you don’t need a script. Just put it under the starter gear.

But I want it to only be given to the player if the button is pressed.

You must put the tool clone inside StarterGear using a ServerScript, you will need to Fire a RemoteEvent once you pressed the button and then, clone it to the StarterGear.

Put a normal script instead of local and next change the

local player = game.Players.(…)

put

local player = script.parent.parent (and .parent until reach one time before the StarterGui)

you can just find a click to give tool in the toolbox section those existed. and you can modify and edit the scripts there to your liking.

You need to use remote events in this situation. You cant/should not use a local script to parent tools in Backpack or StarterGear, it would be a bad practice.

Insert a RemoteEvent in ReplicatedStorage, and rename it to ToolEvent.
Change the code for your LocalScript with this new code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolEvent = ReplicatedStorage:WaitForChild("ToolEvent")
local Button = script.Parent:WaitForChild("TextButton")

Button.Activated:Connect(function()
	ToolEvent:FireServer() -- fires the remote event after button was clicked
end)

Now insert a Server Script in ServerScriptService, and use the following code below:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("ToolEvent")
local Tool = ReplicatedStorage:WaitForChild("ClassicSword")

Event.OnServerEvent:Conenct(function(player)
	if 
		player.Backpack:FindFirstChild(Tool.Name) or 
		player.StarterGear:FindFirstChild(Tool.Name) 
	then -- if tool already exists in backpack or startergear
		return -- stops the function from running
	else -- if it does not exist
		Tool:Clone().Parent = player.Backpack -- clones the tool in backpack
		Tool:Clone().Parent = player.StarterGear -- and then clones the tool in starter gear
	end
end)

And that’s all

5 Likes