I’ve been working creating a special ability for a sword for a while now, and each time have ran into the same problem. I have a local script and a server script.
Local Script:
local player = script.Parent.Parent.Parent.Parent
repeat wait() until player.Character
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local CAS = game:GetService("ContextActionService")
local tool = script.Parent.Parent
local ready = tool.SpecialAbility.Ready
local activated = tool.SpecialAbility.Activated
local equipped = tool.SpecialAbility.Equipped
local canDamage = tool.SpecialAbility.CanDamage
local activationTime = 0.5
local coolDown = 4.5
local specialAttackAnim = tool.SpecialAttack
local specialAttack = humanoid:LoadAnimation(specialAttackAnim)
tool.Equipped:Connect(function()
equipped.Value = true
end)
tool.Unequipped:Connect(function()
equipped.Value = false
end)
local function special(actionName, inputState)
if actionName == "Special Ability" and inputState == Enum.UserInputState.Begin and equipped.Value == true and ready.Value == true then
ready.Value = false
specialAttack:Play()
wait(activationTime)
activated.Value = true
wait(coolDown)
ready.Value = true
activated.Value = false
canDamage.Value = true
end
end
CAS:BindAction("Special Ability", special, false, Enum.KeyCode.Q)
Server Script:
local player = script.Parent.Parent.Parent.Parent
repeat wait() until player.Character
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent.Parent
local damagePart = tool.Blade
local activated = tool.SpecialAbility.Activated
local canDamage = tool.SpecialAbility.CanDamage
local damage = 100
damagePart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and activated.Value and canDamage.Value == true then
canDamage.Value = false
hit.Parent.Humanoid:TakeDamage(damage)
end
end)
The local script is for playing the animation as well as controlling some bool values. The server script is for doing damage. I’ve tried doing these tasks only in local scripts and it has worked, but obviously it will only apply to the client. So, I made the damage script a server script so it applies to all clients. Inside the tool, I have there four bool values, as seen in the local script. My thoughts were that the local script changing those values will allow the server script to read them as well. However, this did not work. The local script is working, but the special ability does not do damage. Here I have a video of me testing out the ability on a dummy with a humanoid object.
As you can see the animation is working perfectly fine, just the dummy is not getting damaged. I would really appreciate someone pointing out what’s wrong with my script.