Are there any alternatives I could use for the Tool.Activated function? If there are please reply to this post with them.
I think the best method is Tool.Activated, but heres an alternative.
local UIS = game:GetService("UserInputService")
script.Parent.Equipped:Connect(function()
print("Equipped")
UIS.InputBegan:Connect(function(input, proc)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Activated")
end
end)
end)
another alternative that i prefer is to use contex action service and bind the action when the tool is equipped and unbind it when the tool is unequipped
as simple as this
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
print("pressed")
end)
end)
Why would you put a connection inside another connection? The signal will just continue to fire endlessly even when the tool is de-equipped and it just creates a lot of connections for every equip anyway. A better way is to set the signal outside and check if the tool is equipped or not by using a boolean
Use user input service and check for taps and clicks. Also, check if the tool is equipped
You can check if the player has performed a touch action by checking inputObject.UserInputType.
We use it in our clan tech for iPad and Android Tablet support.
(Input Map for completion sake)
thank you for the correction @sonic_848
here’s the updated code
local players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local localPlayer = players.LocalPlayer
local mouse = localPlayer:GetMouse()
local tool = script.Parent
local equipped = false
tool.Equipped:Connect(function()
task.wait()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
if not UIS.TouchEnabled then
mouse.Button1Down:Connect(function()
if equipped then
print("pressed")
end
end)
else
UIS.TouchTap:Connect(function()
if equipped then
print("tapped")
end
end)
end
but it really shouldnt be this hard, why dont you just use .Activated?
Whenever I try to use .Activated, it doesn’t work and the code is correct. You can check my latest post and see
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.