My health script is not working as intended, its supposed to be firing the remote event but im getting an Arguement 1 missing or nil error, any help?
local TOOL = script.Parent
local BLADE = TOOL.Blade
local ANIMS = {}
for index, CHILD in pairs(script:GetChildren()) do
if CHILD.Name == "Slash" then
table.insert(ANIMS,CHILD)
end
end
local FIGHT = false
local FRIENDLYFIRE = TOOL.FriendlyFire
local IDLEANIM = nil
local TRAIL = BLADE.Trail
function Slash()
if FIGHT == false then
local HUM = TOOL.Parent:FindFirstChildOfClass("Humanoid")
if HUM then
TOOL.Slashing.Value = true
BLADE.Swing.Pitch = math.random(8,12)/10
BLADE.Swing:Play()
TRAIL.Enabled = true
local SHOUT = script.Grunt:Clone()
SHOUT.Parent = HUM.Parent.Head
SHOUT:Play()
SHOUT.Pitch = math.random(8,12)/10
game:GetService("Debris"):AddItem(SHOUT,2)
local ANIM = HUM:LoadAnimation(ANIMS[math.random(1,#ANIMS)])
ANIM:Play()
FIGHT = true
ANIM.Stopped:Connect(function()
HUM.Health = 100
IDLEANIM:Stop()
game.ReplicatedStorage.StopAnim:FireClient()
wait(0.1)
script.Parent:Destroy()
end)
end
end
end
TOOL.Activated:Connect(function()
Slash()
end)
TOOL.Equipped:Connect(function()
local HUM = TOOL.Parent:FindFirstChildOfClass("Humanoid")
if HUM then
IDLEANIM = HUM:LoadAnimation(script.Idle)
IDLEANIM:Play()
end
end)
TOOL.Unequipped:Connect(function()
if IDLEANIM then
IDLEANIM:Stop()
end
end)
--in this line
game.ReplicatedStorage.StopAnim:FireClient()
--you need to put the player to which you want the event to fire
game.ReplicatedStorage.StopAnim:FireClient(player)
--to get the player you can do this
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(Tool.Parent)
@Pooglies didn’t mention whether it was a localscript or server script, I assume it’s a server script.
To add on once again, FireClient needs a Client to communicate with a specific client (A player object)
--in this line
game.ReplicatedStorage.StopAnim:FireClient()
--you need to put the player to which you want the event to fire
game.ReplicatedStorage.StopAnim:FireClient(player)
--to get the player you can do this
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(Tool.Parent)
game.ReplicatedStorage.StopAnim:FireClient()
Should be changed to game.ReplicatedStorage.StopAnim:FireClient(game.Players:GetPlayerFromCharacter(TOOL.Parent))
(FireClient requires a player to work)
local TOOL = script.Parent
local BLADE = TOOL.Blade
local ANIMS = {}
for index, CHILD in pairs(script:GetChildren()) do
if CHILD.Name == "Slash" then
table.insert(ANIMS,CHILD)
end
end
local FIGHT = false
local FRIENDLYFIRE = TOOL.FriendlyFire
local IDLEANIM = nil
local TRAIL = BLADE.Trail
function Slash(player)
if FIGHT == false then
local HUM = TOOL.Parent:FindFirstChildOfClass("Humanoid")
if HUM then
TOOL.Slashing.Value = true
BLADE.Swing.Pitch = math.random(8,12)/10
BLADE.Swing:Play()
TRAIL.Enabled = true
local SHOUT = script.Grunt:Clone()
SHOUT.Parent = HUM.Parent.Head
SHOUT:Play()
SHOUT.Pitch = math.random(8,12)/10
game:GetService("Debris"):AddItem(SHOUT,2)
local ANIM = HUM:LoadAnimation(ANIMS[math.random(1,#ANIMS)])
ANIM:Play()
FIGHT = true
ANIM.Stopped:Connect(function()
HUM.Health = 100
IDLEANIM:Stop()
game.ReplicatedStorage.StopAnim:FireClient(player)
wait(0.1)
script.Parent:Destroy()
end)
end
end
end
TOOL.Activated:Connect(function()
local player = game:GetService("Players"):GetPlayerFromCharacter(TOOL.Parent)
Slash(player)
end)
TOOL.Equipped:Connect(function()
local HUM = TOOL.Parent:FindFirstChildOfClass("Humanoid")
if HUM then
IDLEANIM = HUM:LoadAnimation(script.Idle)
IDLEANIM:Play()
end
end)
TOOL.Unequipped:Connect(function()
if IDLEANIM then
IDLEANIM:Stop()
end
end)