So i made an attack, everything seems to be working, except the death detection, tried creating an objectvalue, I also have another script that has the leaderstats and detecting if player died. Not sure what I did wrong, the output is not printing any errors.
local rs = game:GetService("ReplicatedStorage")
local Attackevent = rs:WaitForChild("Attackevent")
local attack = game.ServerStorage:WaitForChild("Electroball")
local dmged = false
Attackevent.OnServerEvent:Connect(function(plr)
local char = plr.Character
local hum = plr:FindFirstChild("Humanoid")
local rp = char.PrimaryPart
local newattack = attack:Clone()
newattack.Parent = game.Workspace
newattack.CanCollide = false
newattack.Anchored = false
newattack.Position = rp.CFrame.Position + rp.CFrame.LookVector
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = rp.CFrame.LookVector * 100
bv.Parent = newattack
game.Debris:AddItem(newattack, 5)
newattack.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and plr.Name ~= hit.Parent.Name then
humanoid:TakeDamage(30)
end
end)
newattack.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
local Tagged = Instance.new("ObjectValue")
Tagged.Name = "creator"
Tagged.Value = Player
Tagged.Parent = Hit.Parent.Humanoid
game.Debris:AddItem(Tagged, 2)
end
end)
end)
the other piece of code is
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function()
if Character.Humanoid:FindFirstChild("creator") then
local Player = Character.Humanoid.creator.Value
local Leaderstats = Player.leaderstats
local kills = Leaderstats.Kills
Kills.Value = kills.Value + 1
end
end)
end)
end)