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

What Script do I use to touch a brick to give me a gear?

I have been trying the old script

01	local debounce = false
02	 
03	function getPlayer(humanoid)
04	local players = game.Players:children()
05	for i = 1, #players do
06	if players[i].Character.Humanoid == humanoid then return players[i] end
07	end
08	return nil
09	end
10	 
11	function onTouch(part)
12	 
13	local human = part.Parent:findFirstChild("Humanoid")
14	if (human ~= nil) and debounce == false then
15	 
16	debounce = true
17	 
18	local player = getPlayer(human)
19	 
20	if (player == nil) then return end
21	 
22	script.Parent:clone().Parent = player.Backpack
23	 
24	wait(2)
25	debounce = false
26	end
27	end
28	 
29	 
30	script.Parent.Parent.Touched:connect(onTouch)

This is the one that doesn't work.

So I tried fixing it but it still didn't work. Can you help me?

1 comment

0

"the old script" This is not free model support. You have not shown any attempt to debug it or explain how it works, and also have provided code with deprecated methods. I have marked this as non-constructive and off-topic as this is not for free model help nor will we make a model for you

3 answers

Change line 22 to something to point to where you have your gear such as serverstorage...

game:GetService("ServerStorage").YOURGEAR:clone().Parent = player.Backpack

2 comments

1

Oh so I needed to get service to server storage?

1

Not really, you can put the gear you want to clone where ever you want it. I typically store stuff in server storage as opposed to workspace so it doesn't get picked up or something

What your going to have to do is detect when the part is touched on the server, then clone a tool to their backpack (or character for instant equip).

local Player = game:GetService('Players')

local Tool = script.Tool -- Put the tool in the script
local Part = workspace.Part -- Define the part here

local Debounce = false

Part.Touched:Connect(function(Obj)
	if Debounce then return end
	Debounce = true
	local Player = Players:GetPlayerFromCharacter(Obj.Parent)
	if Player then
		Tool:Clone().Parent = Player.Backpack
		wait(1)
		Debounce = false
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.