I don't know what I could do about the error: ServerScriptService.MainScript:71: attempt to index nil with 'Name'? Here is the script for it: LINE 72 IS THE PROBLEM!
local serverStorage = game:GetService("ServerStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")
local KOValue = "Kills"
local damage = 15
replicatedStorage.ShootEvent.OnServerEvent:Connect(function(player,tool,position,part)
if game.Workspace[player.Name].Humanoid.Health <= 0 then
-- The player is dead, do not do anything
else
local distance = (tool.tip.CFrame.p - position).magnitude
if game.Workspace:FindFirstChild(player.Name.."'s Trajectory") then
game.Workspace:FindFirstChild(player.Name.."'s Trajectory"):Destroy()
end
local trajectory = Instance.new("Part",game.Workspace)
local smoke = serverStorage.SmokeParticle:Clone()
smoke.Parent = tool.Handle
trajectory.BrickColor = BrickColor.new("Institutional white")
trajectory.Material = "SmoothPlastic"
trajectory.Name = player.Name.."'s Trajectory"
trajectory.Transparency = 0.5
trajectory.Anchored = true
trajectory.Locked = true
trajectory.CanCollide = false
trajectory.Size = Vector3.new(0.3,0.3, distance)
for i = 0,distance,6 do
trajectory.CFrame = CFrame.new(tool.Tip.CFrame.p,position) * CFrame.new(0,0,-distance / 2)
wait(0.0001)
end
smoke:Destroy()
if part then
if part.Name == "Head" or part:IsA("Hat") and part.Parent:FindFirstChild("Humanoid").Health > 0 then
replicatedStorage.Headshot:FireClient(player)
damage=30
end
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
else
humanoid:TakeDamage(damage)
if humanoid.Health <= 0 then
player.leaderstats[KOValue].Value = player.leaderstats[KOValue].Value + 1
end
end
wait(0.5)
if trajectory then
trajectory:Destroy()
end
end
end
end)
replicatedStorage.EquipAnimation.OnServerEvent:Connect(function(player,animation)
local newAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
newAnim:Play()
replicatedStorage.UnequipAnimation.OnServerEvent:Connect(function(player,animation)
newAnim:Stop()
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == player.Name.."'s Trajectory" then
v:Destroy()
end
end
end)
replicatedStorage.Reload.OnServerEvent:Connect(function(player,animation)
newAnim:Stop()
local reloadAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
reloadAnim:Play()
end)
end)
function checkBodyType(player,tool)
if game.Workspace[player.Name]:FindFirstChild("LowerTorso") then -- R15
tool.shoot.AnimationId = "rbxassetid://5320645770"
tool.reload.AnimationId = "rbxassetid://5320715605"
return "R15"
end
if game.Workspace[player.Name]:FindFirstChild("Torso") then -- R16
tool.shoot.AnimationId = "rbxassetid://5320789224"
tool.reload.AnimationId = "rbxassetid://5320798913"
return "R6"
end
end
replicatedStorage.CheckBodyType.OnServerInvoke = checkBodyType()

5 comments
Oh, also you don't really need to use game.Workspace, you can just use the workspace variable provided by Roblox. It's really preference at the end of the day, it just looks cleaner.
It says it for line 72, i forgot to put that in their
Also, your answer has nothing to do with "Attempt to index nil with 'Name' in my gun script"
It sure does, please look at your code. I literally just tested in studio.
Does work lol. You were right.