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)
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.
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)