What am I doing wrong here?

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)
2 Likes

Does the output say what specific line is erroring?

1 Like

33, which is the line where it fires the “StopAnim”

1 Like
--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)
2 Likes

To add on to this, it appears that he is using a LocalScript and is using FireClient, according to:

It clearly states:

Since this function is used to communicate from the server to the client, it will only work when used in a script.

no this is a server script i think or im not sure

It is a server script. You are correct.

@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)

so the you need to do what i said in my reply

There is a client, this is the client script.

local player = game.Players.LocalPlayer

repeat wait(1) until player.Character

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "3392804142"

local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:connect(function()
	animtrack:Play()
end)

script.Parent.Unequipped:connect(function()
	animtrack:Stop()
end)

game.ReplicatedStorage.StopAnim.OnClientEvent:connect(function()
	animtrack:Stop()
end)

try doing what i said in this reply

--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)

I got a new error, “Player arguement must be a player object”

game.ReplicatedStorage.StopAnim:FireClient()
Should be changed to
game.ReplicatedStorage.StopAnim:FireClient(game.Players:GetPlayerFromCharacter(TOOL.Parent))
(FireClient requires a player to work)

2 Likes

here try using this on server

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)

i just edited this btw

The humanoids health does not fill back up to 100, why is that?

is the error gone though ? #30character limit

Yeah it is. The error is gone but the health isnt restored

Make sure the Health script under character is there and enabled

try chaging this line on the server:

HUM.Health = 100
--to this :
HUM.Health = HUM.MaxHealth

It did not work sadly, any other ways, I am confused because this should work?