So basically im making a ability thats in a tool, and I just finished the ability, however. . .
the problem is that my equipped checker is haulting the entire script
local tool = script.Parent
local UIP = game:GetService("UserInputService")
local Remote = tool:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer
local char = player.Character
local root = char:WaitForChild("HumanoidRootPart")
local Debounce = 1
local anim = script.Animation
local track = char.Humanoid:LoadAnimation(anim)
local ic = script.InstaCast
UIP.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E and Debounce == 1 then
print("Local Script Recieved Input . . .")
Debounce = 2
spawn(function()
ic = true
wait(0.41)
ic = false
end)
root.Anchored = true
track:Play()
wait(0.15)
track:AdjustSpeed(0)
end
end)
UIP.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E and Debounce == 2 then
repeat wait() until ic == false
print(". . . Sending To Server")
track:AdjustSpeed(1)
Debounce = 3
Remote:FireServer(char, player, UIP, tool)
wait(4) -- cooldown
Debounce = 1
end
end)
this is the script, I tried implementing integers like how debounce is used, and also tried external bool values, I tried server scripts and locals, however it never worked…
if you talking about being tool in inventory of player, you can just check if it keeps in player backpack or player model. if nor then tool not being equipped, makes sense
This is a very basic and easy to edit system for monitoring whenever a Tool instance is equipped by the player (or if a instance is added the player with the object class of Tool I guess)
This script should be placed in a Script instance within ServerScriptService . The function onToolEquipped is connected to each player that joins the game.
-- Function to detect when a player is holding a tool
local function onToolEquipped(player)
player.CharacterAdded:Connect(function(char)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
print(player.Name .. " has equipped a tool: " .. child.Name)
-- Add additional logic here for when the player equips a tool
end
end)
character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
print(player.Name .. " has unequipped a tool: " .. child.Name)
-- Add additional logic here for when the player unequips a tool
end
end)
end)
end
-- Connect the function to each player that joins the game
game.Players.PlayerAdded:Connect(onToolEquipped)
It waits for the player’s character to be added and then listens for any tools (objects of class Tool ) being added to or removed from the character’s model. When a tool is equipped or unequipped, it prints a message to the output. You can replace the print statements with your own custom logic depending on what you want to happen when a tool is equipped or unequipped.
I recommend you do something like this (LocalScript inside of your Tool):
local contextActionService = game:GetService("ContextActionService")
local tool = script.Parent
tool.Equipped:Connect(function()
contextActionService:BindAction(tool.Name, function(_, inputState)
if inputState == Enum.UserInputState.Begin then
-- Write the code you want to happen when the player presses 'E' inside here, as an example:
print(true)
else
-- Write the code you want to happen when the player stops pressing 'E' inside here, example:
print(false)
end
end, false, Enum.KeyCode.E)
end)
tool.Unequipped:Connect(function()
contextActionService:UnbindAction(tool.Name)
end)
It will only run the code if the player presses or depresses E while your Tool is equipped