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

How do I make items go to the players backpack after I touch a block?

When I was working on my game, I decided I would have a block that gives the player an item and teleports them to a certain place. For some reason, however, the item giver isn't working. I made the script a local script.

local teleblox = game.Workspace.BloxxerStatueModel.TheBStatue.Teleporter
local Fight = game.ServerStorage.Fight
local FightClone = Fight:Clone()

local function pint()
	FightClone.Parent = game.Players.LocalPlayer.Backpack
	print("oml it worked")
end

script.Parent:findFirstChild("Humanoid")(pint)

3 comments

0

How exactly will the block give the player the tool? Ontouch or OnClick?

0

server storage isn't keeping the tool I place in it so I'm putting it in replicated storage

0

Oh sorry, the block would give the player a weapon on touch, sorry for the wait.

2 answers

You need an event that will detect when the player is touching the block. In this case, Touched should do.

local teleblox = game.Workspace.BloxxerStatueModel.TheBStatue.Teleporter
local Fight = game.ServerStorage.Fight
local FightClone = Fight:Clone()

 

script.Parent.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
    FightClone.Parent = game.Players.LocalPlayer.Backpack

    print("oml it worked")

   end
end)

Assuming that you are placing the script within whatever block you need to touch.

3 comments

0

I would recommend using game:GetService() instead of calling upon it directly. In this case, local Fight = game:GetService("ServerStorage")

0

Thanks! I knew I was missing one thing!

0

So, tried typing this in and checking things, but it didn't work some how.

Assuming you want to use a touch event, here is what I made.

local teleblox = game.Workspace:WaitForChild('Teleporter')
local Fight = game.ReplicatedStorage:WaitForChild('Fight')
local tp = -23.36, 0.5, 26.03
debounce = 0
function pint(hit)
	if debounce == 0 then
	debounce = 1
	if hit.Parent:FindFirstChild('Humanoid') ~=nil then
	local pn = hit.Parent.Name
	local p = game.Players:FindFirstChild(pn)
	local FightClone = Fight:Clone()
    FightClone.Parent = p.Backpack
	hit.Parent:FindFirstChild('HumanoidRootPart').Position = Vector3.new(-23.36, 0.5, 26.03)
    print("ommeeee gaaawdd it worked")
wait(1)
debounce = 0
end
end
end
script.Parent.Touched:Connect(pint)

p.s - sorry it took so long

2 comments

0

woops change the Vector3.new(-23.36, 0.5, 26.03) to Vector3.new(tp)

0

Oh no its fine. Im new to the helpers thing and I keep checking late

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