How can I make it so when you equip a tool you enable a local script

I have a local script that uses user input service to do stuff when u press certain keys, but I only want that stuff to happen when a certain tool is equipped.

What I tried to do was adding a local script inside the tool, and when the tool is equipped set the UIS script’s disabled to false, and when the tool is unequipped set it to true, but that didn’t work for some reason, how could I do it?

(I tried putting the UIS stuff inside the tool’s local script, and using connections, to connect when you equip and disconnect when u unequip, but it did not work)

1 Like
tool = script.Parent
tool.Equipped:Connect(function()
       script.Parent.LocalScript.Disabled = false
end)
2 Likes
local tool = script.Parent
local ofaLocal = tool:WaitForChild("OFA (Local)")

------------------------------------

tool.Equipped:Connect(function()
	
	ofaLocal.Disabled = false
	
end)

tool.Unequipped:Connect(function()
	
	ofaLocal.Disabled = true
	
end)

this doesn’t work

local tool = script.parent

if tool.Equipped:Connect(function()
script.parent.localscript.disabled = false
end)

tool.Unequipped:Connect(function()
script.parent.localscript.disabled = true
end)

.Disabled is not the right way to solve this. My suggestion is to handle this in the same script as the UIS script, using a local variable and Equipped/Unequipped:Connect as a switch, while checking at every other function if Equipped = true, and return end if it is false.

1 Like

I tried this, I made a variable and set it to true when equipped and false when unequipped, and then in the UIS.InputBegan connected function I checked if that variable was false, if it was it would return, but when I equipped the tool I still couldn’t press the keys

eae mano kkkkkk tu e br ne? essa script ai ta toda errada velho

Strange. Did you put the local variable outside the functions and did you not accidentally redefine the variable within the function? This is within my knowledge the only way to detect if you’re actually using the tool. Does your tool also have a handle? If it doesn’t, .Equipped cannot be detected.

3 Likes

fazer o que mano eu to no celular ta dificil pc quebrou ai não tenho os comandos decorados, também não sou tão avançado sabe to aprendendo pra eu conseguir fazer jogo daora ai eu fico no developer hub e não entendi muito bem o que você queria fazer.

1 Like

DUDE OMG THANK YOU SO MUCH, i forgot to unable Requires Handle, that might be it!!!

2 Likes

dboa mano, se quiser ajuda cola no discord

ta tranquilo mano eu nao mexo muito com uis, eu uso mais valores,touches, prints e um pouco de low polygon

porque também nunca entrei em projetos serios

eu posso ajudar em qualquer coisa, ShinsokuDev#3661, se quiser ajuda so chamar

beleza mano eu to aprendendo pra eu fazer um jogo daora e tmb to aprendendo fazer bot no discord. Vou te adicionar