ive been tryin to figure out how to add a parameter where the player has to have a specific tool equipped for a script to work but i havnt been able to do that so im drawin a blank and asking here for help
heres my script
local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://16081920089"
local isplaying = false
local plr = game.Players.LocalPlayer
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local animplay = humanoid:LoadAnimation(animation)
local replicatedStorage = game.ReplicatedStorage
local fireBlast = replicatedStorage.fireBlast
local function onKeyPress(input)
local direction = workspace.CurrentCamera.CFrame.LookVector
if input.KeyCode == Enum.KeyCode.R then
if isplaying == false then
isplaying = true
animplay:Play()
animplay.Stopped:Connect(function()
isplaying = false
end)
fireBlast:FireServer(direction)
end
end
end
When a player equips a tool, that tool appears inside the character model, so you can try to find the tool inside the character, using “:FindFirstChild(‘’)”
I think someone already explained “Kult” solution should fix the issue but I think you need to check if the player’s character has the tool as a child like this:
local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://16081920089"
local isplaying = false
local char = player.Character or player.CharacterAdded:Wait() -- Wait for character if not loaded
local humanoid = char:WaitForChild("Humanoid")
local animplay = humanoid:LoadAnimation(animation)
local replicatedStorage = game.ReplicatedStorage
local fireBlast = replicatedStorage:WaitForChild("fireBlast")
-- Name of the tool required to be equipped
local requiredToolName = "YourToolNameHere" -- Replace 'YourToolNameHere' with the actual name of your tool
local function onKeyPress(input)
-- Check if the required tool is equipped
local requiredToolEquipped = char:FindFirstChild(requiredToolName) and char[requiredToolName].IsA(char[requiredToolName], "Tool")
-- Only proceed if the required tool is equipped
if requiredToolEquipped then
local direction = workspace.CurrentCamera.CFrame.LookVector
if input.KeyCode == Enum.KeyCode.R then
if not isplaying then
isplaying = true
animplay:Play()
animplay.Stopped:Connect(function()
isplaying = false
end)
fireBlast:FireServer(direction)
end
end
end
end
-- Connect the onKeyPress function to the UserInputService
userInputService.InputBegan:Connect(onKeyPress)