I am trying to make a part and if you touch it, it will give you a tool.
How would I give a player a tool by script?
3 answers
you should put the tool inside replicatedstorage, and then you have to clone it and parent it to the player's backpack.
2 comments
just make a simple script that detects if a humanoid touched the part and then clone the tool to his backpack
Find the humanoid is a bad pratice. The best way is using :FindFirstAncestorWhichIsA("Model") on the hit part and try to find if it's a character with GetPlayerFromCharacter a method of the PlayerService
Hi I made a tool system for you. https://www.roblox.com/library/10630206924/Tool-System After inserting put your tool in ServerStorage. Then Copy the name of the tool and go to script in the model and enter the name of your tool.
You should make a Script inside the Part that is supposed to be touched that Clones your Tool from the ReplicatedStorage into the Players Backpack.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage.Weapons.Sword
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local Character = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Character)
if not Player.Backpack:FindFirstChild(Sword.Name) then
local SwordClone = Sword:Clone()
SwordClone.Parent = Player.Backpack
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
like one that also regens the part when you get the tool?