So I have a script in ServerScriptStorage named 'SwordServer' which basically handles the damage of the different swords. I also have a script in the sword named 'Client' and a RemoteEvent in ReplicatedStorage named 'Damage'. Before I made a weapon shop, I had all my swords in StarterPack and everything worked fine. It was when I put most of my swords in the ReplicatedStorage for the weapon shop that this error occured. Only the StarterSword in the StarterPack seems to work. It states that there is an error in line 30 of the SwordServer where it attempts to index nil with 'Name'. Please help.
SwordServer Script:
local CanAttack = true
local weaponsAndDamages = {}
weaponsAndDamages ["StarterSword"] = 45
weaponsAndDamages ["Hammer"] = 85
weaponsAndDamages ["Scythe"] = 55
weaponsAndDamages ["TripleBladeScythe"] = 220
weaponsAndDamages ["HeavySword"] = 160
weaponsAndDamages ["Dagger"] = 35
weaponsAndDamages ["GoldenDagger"] = 75
weaponsAndDamages ["Spear"] = 60
weaponsAndDamages ["NightmareBlade"] = 80
local weaponsAndRates = {}
weaponsAndRates ["StarterSword"] = 0.75
weaponsAndRates ["Hammer"] = 1
weaponsAndRates ["Scythe"] = 0.75
weaponsAndRates ["TripleBladeScythe"] = 1.3
weaponsAndRates ["HeavySword"] = 1.5
weaponsAndRates ["Dagger"] = 0.6
weaponsAndRates ["GoldenDagger"] = 0.8
weaponsAndRates ["Spear"] = 0.85
weaponsAndRates ["NightmareBlade"] = 0.75
local lastAttack = {}
game.ReplicatedStorage.Damage.OnServerEvent:Connect(function(player, hit)
local weapon = player.Character:FindFirstChildWhichIsA("Tool") -- obtain the sword of the player attacking
if hit.Parent:FindFirstChild("Humanoid") ~= nil and player.Character ~= nil then
if hit.Parent.Humanoid.Health > 0 and player.Character.Humanoid.Health > 0 then -- check if the users are alive, we don't want dead players dealing damage, or players dealing damage to dead players.
if lastAttack[player.Name] == nil or tick() - lastAttack[player.Name] > weaponsAndRates[weapon.Name] then
if (hit.Parent.HumanoidRootPart.Position-player.Character.HumanoidRootPart.Position).magnitude < 40 then -- went with 40 just in case of serious latency. You can tweak this if wanted.
lastAttack[player.Name] = tick()
if weapon ~= nil then -- make sure it's not nil
hit.Parent.Humanoid:TakeDamage(weaponsAndDamages[weapon.Name])
weapon.Handle.Swing:Play() -- You want to play the hit noise on the sword of the player who is attacking, not the sword in the StarterPack.
end
end
end
end
end
end)
game.ReplicatedStorage.Damage.OnServerEvent:Connect(function(player, hit)
local weapon = player.Character:FindFirstChildWhichIsA("Tool")
if hit.Parent:FindFirstChild("Humanoid") ~= nil and player.Character ~= nil then
if hit.Parent.Humanoid.Health > 0 and player.Character.Humanoid.Health > 0 then
local damage = (weaponsAndDamages[weapon.Name]) -- we create a variable which stores the damage inside of it, i randomized the damage between 5 and 20
if CanAttack == true then
CanAttack = false
local indicator = game:GetService("ReplicatedStorage"):FindFirstChild("DmgIndicator") -- we put the dmgindicator which in in the replicatedstorage inside a variable
if indicator then -- we check whether the indicator exists, if so then...
local gui = indicator:Clone() -- we clone it and store the cloned version inside a variable
gui.Parent = hit.Parent:FindFirstChild("HumanoidRootPart") -- we put the cloned version inside the enemy's rootpart
gui.Damage.Text = "-"..tostring(damage) -- we set the damage text to the damage we'll deal
gui.StudsOffset = Vector3.new(math.random(-2, 2), math.random(-2, 2), math.random(-2, 2)) -- we position our gui randomly on the enemy's body (between -2 and 2 studs)
wait(weaponsAndRates[weapon.Name])
game.Debris:AddItem(gui,0.1)
CanAttack = true -- we will destroy that indicator after 2 seconds
end
end
end
end
end)
Client script:
wait(1)
script.Parent.Equipped:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
wait(0.1)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)
--//Attacking Animations\\--
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local CanAttack = true
local Anim_Name = "Attack"
local Audio = script.Parent:WaitForChild("Handle"):WaitForChild("Swing")
local Attack_Animations = script.Parent:WaitForChild("Animations")
local Attack_Num = 1
local blade = script.Parent.SwordBlade
blade.Touched:Connect(function(hit)
if CanAttack == false then
game.ReplicatedStorage.Damage:FireServer(hit)
end
end)
Tool.Activated:Connect(function()
local Animation = script.Parent.Parent.Humanoid:LoadAnimation(Attack_Animations[Anim_Name..Attack_Num])
if CanAttack == true then
CanAttack = false
Animation:Play()
Audio:Play()
wait(0.75)
CanAttack = true
if Attack_Num == 1 then
Attack_Num = Attack_Num + 1
else if Attack_Num == 2 then
Attack_Num = 1
end
end
end
end)
Tool.Deactivated:Connect(function()
script.Parent.Equipped:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
wait(0.1)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)
end)
Script inside the shop UI that gives the scythe:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Coins.Value >= 100 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 100
game.ReplicatedStorage.Scythe:Clone().Parent = player:WaitForChild("Backpack")
end
end)
Error in line 30 of SwordServer

2 comments
Do you know witch 'Name' it is referring too? That might help figure out the problem. Try and substitute [player.Name] with ["UsernameHere"], its a defined value and will find the issue.
when i do that it only shows up with table index is nil