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.

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)
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.

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.

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.

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

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