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

How to give a gear when touching a part?

Asked by
Jxdenx 45
8 years ago

I made this script:

local part = script.Parent local touched = false function OnTouch(Brick) local char = game.Players.LocalPlayer if touched == false then touched = true game:service'InsertService':LoadAsset(16688968):children()[1].Parent=char.Character wait(5) touched = false end end

part.Touched:connect(OnTouch)

But this error appears:

'Unable to find module for asset id'

Help?

1 answer

Log in to vote
0
Answered by
Vezious 310 Moderation Voter
8 years ago
Edited 8 years ago

Can you have the tool already instead of having to Insert it? If so:

01local Part = game.Workspace:FindFirstChild("Part")
02local Tool = script:FindFirstChild("Tool")
03local Debounce = false
04if Tool and Part then
05Part.Touched:connect(function(Part)
06local Humanoid = Part.Parent:FindFirstChild("Humanoid")
07if Humanoid and Debounce == false then
08Debounce = true
09local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
10if Player then
11local ClonedTool = Tool:Clone()
12ClonedTool.Parent = Player.Backpack
13end
14wait()
15Debounce = false
16end
17end)
18end

Sorry if it's difficult to read. I don't like my scripts tabbed. Yeah, I know, I'm weird.

Anyways, what it does is: Check if There is Humanoid, and if there is a Player. If there is, it clones the tool, and places it into the Player's Backpack.

What I highly suggest is preventing it from making more than one copy of the clone.

If you'd like to prevent it from making multiple copies:

1local CharacterHasTool = Part.Parent:FindFirstChild(Tool.Name)
2local PlayerHasTool = Player.Backpack:FindFirstChild(Tool.Name)
Ad

Answer this question