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
7 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
7 years ago
Edited 7 years ago

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

local Part = game.Workspace:FindFirstChild("Part")
local Tool = script:FindFirstChild("Tool")
local Debounce = false
if Tool and Part then
Part.Touched:connect(function(Part)
local Humanoid = Part.Parent:FindFirstChild("Humanoid")
if Humanoid and Debounce == false then
Debounce = true
local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if Player then
local ClonedTool = Tool:Clone()
ClonedTool.Parent = Player.Backpack
end
wait()
Debounce = false
end
end)
end

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:

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

Answer this question