You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
A blocking lightsaber -
What is the issue? Include screenshots / videos if possible!
My inputservice “IsKeyDown” says “unable to cast token to token” -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes, didnt work
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local BlockCooldown = false
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local Animation = script:WaitForChild("swing1")
local Equipped
Tool.Equipped:Connect(function()
Equipped = true
end)
Tool.Unequipped:Connect(function()
Equipped = false
end)
UserInputService.InputBegan:Connect(function(Input, Processed) -- attack
if Processed then return end
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
if Equipped then
local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
local plrhuman = player.Character:FindFirstChild("Humanoid")
local anim = script.swing1
local setanim = anim:Clone()
setanim.Parent = plrhuman
local animtrack = plrhuman:LoadAnimation(setanim)
animtrack:Play()
end
end
end)
UserInputService.InputEnded:Connect(function(input) -- detect if block button is up
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if holdingblock == false then return end
holdingblock = false
end
end)
UserInputService.InputEnded:Connect(function(Input, Processed)
if Processed then return end
if Input.UserInputType == Enum.UserInputType.MouseButton2 then
holdingblock = false
end
if Input.UserInputType == Enum.UserInputType.MouseButton2 then -- block
if Equipped then -- second
holdingblock = true
local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
local plrhuman = player.Character:FindFirstChild("Humanoid")
local anim = script.block1
local setanim = anim:Clone()
setanim.Parent = plrhuman
local animtrack = plrhuman:LoadAnimation(setanim)
print("it played but... nothing?")
animtrack:Play()
animtrack.Stopped:Connect(function()
while true do
wait()
if UserInputService:IsKeyDown(Enum.UserInputType.MouseButton2) then
animtrack:Play()
repeat wait()
until animtrack.Stopped == true
elseif holdingblock == false then break end
end
BlockCooldown = true
wait(5)
BlockCooldown = false
end)
end
end
end)