Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I give a player a tool by script?

I am trying to make a part and if you touch it, it will give you a tool.

1 comment

0

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

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

0

just make a simple script that detects if a humanoid touched the part and then clone the tool to his backpack

0

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

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.