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 it so my script only works when someone is holding a certain tool?

I'm trying to fix something which is taking me ages, basically- I'm trying to make it so that a script of mine only works when I have a certain tool in my hand.


model = script.Parent.Parent

backup = model:clone()
enabled = true


function regenerate()
 model:remove()


 wait(1)--


 model = backup:clone()
 model.Parent = game.Workspace
 model:makeJoints()


 script.Disabled = true
 script.Parent.BrickColor = BrickColor.new(26)--Black
 wait(1)
 script.Parent.BrickColor = BrickColor.new(104)--Purple
 script.Disabled = false
end


function onHit(hit)
 if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
  regenerate()
 end
end


script.Parent.Touched:connect(onHit)


1 comment

0

(This script is supposed to regenerate a model when touching a part, it does that except I'm just trying to make it that it only regenerates when someone has a certain tool in their hand, and touches the brick that regenerates it.

1 answer

it is easy. just do this,

copy this script to the moving part inside the tool. so script.Parent is the moving part in that tool. when it touches something, do that onHit() thing!

but then, you need to fix something. model is, of course, not a script.parent.parent anymore, it has to be derived from workspace.

1 comment

0

The regeneration script & destroying tool in backpack works perfectly fine. Just the script needing to be activated with someone with the specific tool. If you were trying to say that, please explain it again because I don't understand what you genuinely mean.

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