Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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.

01local teleblox = game.Workspace.BloxxerStatueModel.TheBStatue.Teleporter
02local Fight = game.ServerStorage.Fight
03local FightClone = Fight:Clone()
04 
05local function pint()
06    FightClone.Parent = game.Players.LocalPlayer.Backpack
07    print("oml it worked")
08end
09 
10script.Parent:findFirstChild("Humanoid")(pint)
0
How exactly will the block give the player the tool? Ontouch or OnClick? WyattagumsBackUp 5 — 5y
0
server storage isn't keeping the tool I place in it so I'm putting it in replicated storage WyattagumsBackUp 5 — 5y
0
Oh sorry, the block would give the player a weapon on touch, sorry for the wait. fighterkirbyzx 102 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

01local teleblox = game.Workspace.BloxxerStatueModel.TheBStatue.Teleporter
02local Fight = game.ServerStorage.Fight
03local FightClone = Fight:Clone()
04 
05 
06 
07script.Parent.Touched:Connect(function(hit)
08   if hit.Parent:FindFirstChild("Humanoid") then
09    FightClone.Parent = game.Players.LocalPlayer.Backpack
10 
11    print("oml it worked")
12 
13   end
14end)

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

0
I would recommend using game:GetService() instead of calling upon it directly. In this case, local Fight = game:GetService("ServerStorage") superawesome113 112 — 5y
0
Thanks! I knew I was missing one thing! fighterkirbyzx 102 — 5y
0
So, tried typing this in and checking things, but it didn't work some how. fighterkirbyzx 102 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

01local teleblox = game.Workspace:WaitForChild('Teleporter')
02local Fight = game.ReplicatedStorage:WaitForChild('Fight')
03local tp = -23.36, 0.5, 26.03
04debounce = 0
05function pint(hit)
06    if debounce == 0 then
07    debounce = 1
08    if hit.Parent:FindFirstChild('Humanoid') ~=nil then
09    local pn = hit.Parent.Name
10    local p = game.Players:FindFirstChild(pn)
11    local FightClone = Fight:Clone()
12    FightClone.Parent = p.Backpack
13    hit.Parent:FindFirstChild('HumanoidRootPart').Position = Vector3.new(-23.36, 0.5, 26.03)
14    print("ommeeee gaaawdd it worked")
15wait(1)
16debounce = 0
17end
18end
19end
20script.Parent.Touched:Connect(pint)

p.s - sorry it took so long

0
woops change the Vector3.new(-23.36, 0.5, 26.03) to Vector3.new(tp) WyattagumsBackUp 5 — 5y
0
Oh no its fine. Im new to the helpers thing and I keep checking late fighterkirbyzx 102 — 5y

Answer this question