I want to make it so when a player equips certain tools, which are skills for a fighting game(skills being identified by a BoolValue inside the tool called “isSkill” being true/false), those with the value set to true perform what they are supposed to upon being equipped rather than requiring a Player to click to use it.
Furthermore, the tool should be unequipped after the skill is used/completed, if possible. There doesn’t have to be any delay accounted for, simply just unequipping the tool about a second after it is initially equipped.
My tools are not set up in any fancy way. They’re located in the ServerStorage/StarterPack, and do their thing when a player takes them out and clicks with their mouse. I am a very new scripter though, so even these “basics” are foreign and difficult for me.
I’ve considered using scripts inside of StarterPlayer, but I’m not sure how to nor if that is even the solution. Please help!
Tool.Equipped:Connect(function()
-- Code here
end)
To make Tool dequip you can do this:
local plr = game:GetService('Players').LocalPlayer
if plr.Character then
plr.Character:WaitForChild('Humanoid'):UnequipTools()
end
To make tool activate and dequip after second do this:
Tool.Equipped:Connect(function()
delay(1,function()
local plr = game:GetService('Players').LocalPlayer
if plr.Character then
plr.Character:WaitForChild('Humanoid'):UnequipTools()
end
end)
-- code here
end)
If you want to disable player’s ability to equip anything else you can simply do this
game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
In this case the first argument is CoreGuiType (Core gui that will be disabled or enabled) and second argument is the Enabled (True) or Disabled (False)
Is there any way that instead of needing to go tool-by-tool (there are roughly 90 of them, and while I can do that, it would take some time), this can be done in a way that checks the condition of checking for a value called “isSkill” being true or false?
Essentially, I’m trying to replicate those battleground games with the “Auto Use Skill” features for my game. I realize that my above explanation was quite complicated and seemed to have made it hard to understand my goal.
Essentially, yes. Every tool has the value “isSkill” inside of it, and some (being the skills) have it set to “true” while other tool-types, like weapons, have it set to “false.”
local WhereAllToolsIs = game.StarterPack
for i,v in pairs(WhereAllToolsIs:GetChildren()) do
if v:IsA('Tool') then
if v:FindFirstChild('isSkill') then
if v.isSkill == true then
-- some function
end
end
end
end
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
for index, tool in player.Backpack:GetChildren() do
if not (tool:IsA("Tool") ) then
return
end
local isSkill = tool:FindFirstChild("isSkill")
if not isSkill and isSkill.Value == false then
return
end
tool.Equipped:Connect(function()
-- perform attack
task.delay(<NUMBER>, function()
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then
return
end
humanoid:UnequipTools()
end)
end)
end
(i didn’t test this code so don’t scream at me if it doesn’t work)
It will not perfectly work with multiple abilities and vfx, to make it work with multiple tools with other abilities you need to make system with remote events and modulescripts