I was trying to make it so that when the player clicks the TextButton, there is a new Tool in the StarterPack. I had no clue how to do this, but I tried it anyway. This is the code I came up with.
script.Parent.MouseButton1Click:Connect(function(plr)
local T = Instance.new("Tool", game.StarterPack)
T.Name = "Tool1"
local R = Instance.new("Part", T)
T.Name = "Handle"
R.Parent = T
end)
There were no error messages in the output box. I’m new to scripting, and don’t know too much! Please help!
MouseButton1Click does not have any parameters, so you cannot get the player that clicked it. You should use a LocalScript if you aren’t, and use LocalPlayer, to give it to their backpack, and not StarterPack, like @Spraden said.
Additionally, it may also be a good idea to have the server give the tool to the player, by using a RemoteEvent.
but you can add tools inside StarterGear, but it would need Clone to do that.
local tool -- the tool you want to move into backpack
local toolClone = tool:Clone()--clones the tool, the Achievable property inside the tool should be set to True for it to get cloned
toolClone.Parent = game.Players.LocalPlayer.Backpack--you can remove this, but this is if you want it to be added into the backpack without resetting to get it.
toolClone.Parent = game.Players.LocalPlayer.StarterGear