Attempt to index nil with "Name"

Server Script:

local tiger = script.Parent
local humanoid = tiger:WaitForChild("Humanoid")
local debounce = true
local attackAnim = humanoid:LoadAnimation(script.Attack)
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function()
	print(0)
	for i,player in pairs(game.Players:GetPlayers()) do
		print(1)
		local target = player.Character
		local distance = (tiger.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
		if distance <= 8  and target and target ~= tiger and humanoid.WalkSpeed ~= 0 and debounce == true and target.Name ~= "Tiger" and target.Name ~= "Tiger1" then
			debounce = false
			print(2)
			tiger.Head.AttackSound:Play()
			local playerDeath = game.ReplicatedStorage:WaitForChild("playerdeath")
			local KillFeed = game.ReplicatedStorage:WaitForChild("KillFeed")
			local player = game.Players:GetPlayerFromCharacter(target)
			local tigerplayer = game.Players:GetPlayerFromCharacter(tiger)
			playerDeath:FireClient(player,tiger)
			attackAnim:Play()
			attackAnim.Stopped:Wait()
			target.Humanoid.Health = 0
			tigerplayer.leaderstats.Meat.Value += 1
			KillFeed:FireClient(tigerplayer,player)
			wait(10)
			debounce = true
		end
	end
end)


Local Script:

game.ReplicatedStorage.KillFeed.OnClientEvent:Connect(function(tigerplayer,player)
	local thumb1 = Enum.ThumbnailType.HeadShot
	local thumb2 = Enum.ThumbnailSize.Size420x420
	script.Parent.Visible = true
	script.Parent.PlayerName.Text = player.Name
	script.Parent.PlayerImage.Image = game:GetService("Players"):GetUserThumbnailAsync(player.UserId,thumb1,thumb2)
end)

Error:

Players.Player2.PlayerGui.KillFeed.Frame.LocalScript:5: attempt to index nil with 'Name'

Why isn’t it working?

The player doesn’t exist. If it is indexing nil with .Name and it is a player object, then it probably means the Player is nil.

Maybe because I am killing him, so should I before I am killing him?

What is the tiger variable? Is it the player or another object?

the Tiger is my player so you and the player is the one that you kill!

When firing a RemoteEvent to the client on the server you’ve to pass the actual Player argument first that the RemoteEvent would land on, you’re currently actually passing one argument not two.

Example:

-- Server
local Player = -- The player who  you're going to fire  a remote event to.
local OtherPlaer = -- any other argument
RemoteEvent:FireClient(Player, OtherPlayer)
-- Client
local Player = game.Players.LocalPlayer

RemoteEvent.OnServerEvent:Connect(function(OtherPlayer)

end)

how to fix it, because I don’t know how?

So just don`t give the player as a parameter and only the other ok

2 Likes

Here is the new code, this will fix your issue.

local tiger = script.Parent
local humanoid = tiger:WaitForChild("Humanoid")
local debounce = true
local attackAnim = humanoid:LoadAnimation(script.Attack)
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function()
	print(0)
	for i,player in pairs(game.Players:GetPlayers()) do
		print(1)
		local target = player.Character
		local distance = (tiger.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
		if distance <= 8  and target and target ~= tiger and humanoid.WalkSpeed ~= 0 and debounce == true and target.Name ~= "Tiger" and target.Name ~= "Tiger1" then
			debounce = false
			print(2)
			tiger.Head.AttackSound:Play()
			local playerDeath = game.ReplicatedStorage:WaitForChild("playerdeath")
			local KillFeed = game.ReplicatedStorage:WaitForChild("KillFeed")
			local player = game.Players:GetPlayerFromCharacter(target)
			local tigerplayer = game.Players:GetPlayerFromCharacter(tiger)
			playerDeath:FireClient(player,tiger)
			attackAnim:Play()
			attackAnim.Stopped:Wait()
			target.Humanoid.Health = 0
			tigerplayer.leaderstats.Meat.Value += 1
			KillFeed:FireClient(tigerplayer,player)
			wait(10)
			debounce = true
		end
	end
end)

LocalScript

game.ReplicatedStorage.KillFeed.OnClientEvent:Connect(function(player)
	local thumb1 = Enum.ThumbnailType.HeadShot
	local thumb2 = Enum.ThumbnailSize.Size420x420
	script.Parent.Visible = true
	script.Parent.PlayerName.Text = player.Name
	script.Parent.PlayerImage.Image = game:GetService("Players"):GetUserThumbnailAsync(player.UserId,thumb1,thumb2)
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.