So I'm trying to make a script that goes in every weapon to make it detect kills. Can someone help me make a script I can put that makes kills get detected. Here is a script I put in ServerScriptService. Also where in the weapon do I put it? In WeaponSystem? Thanks.
local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") local winsStore = DataStoreService:GetDataStore("winsStore") local killStore = DataStoreService:GetDataStore("killStore") local deathStore = DataStoreService:GetDataStore("deathStore") local coinsStore = DataStoreService:GetDataStore("coinsStore") Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local hasDied = Instance.new("BoolValue", character) hasDied.Name = "HasDied" hasDied.Value = false character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function() if character.Humanoid.Health <= 0 and not character.HasDied.Value then player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1 end end) end) player:WaitForChild("leaderstats") local cash = Instance.new("IntValue", player) cash.Name = "Cash" local wins = Instance.new("IntValue", player.leaderstats) wins.Name = "Wins" local kills = Instance.new("IntValue", player.leaderstats) kills.Name = "Kills" local deaths = Instance.new("IntValue", player.leaderstats) deaths.Name = "Deaths" local success, error = pcall(function() cash.Value = coinsStore:GetAsync(player.UserId) wins.Value = winsStore:GetAsync(player.UserId) kills.Value = killStore:GetAsync(player.UserId) deaths.Value = deathStore:GetAsync(player.UserId) end) if not success then warn("Error while finding data") warn(error) end end) Players.PlayerRemoving:Connect(function(player) local success, error = pcall(function() coinsStore:SetAsync(playe wr.UserId, player.Cash.Value) winsStore:SetAsync(player.UserId, player.leaderstats.Wins.Value) killStore:SetAsync(player.UserId, player.leaderstats.Kills.Value) deathStore:SetAsync(player.UserId, player.leaderstats.Deaths.Value) end) if not success then warn("Error while setting data") warn(error) end end) -- server is closing, sync everything game:BindToClose(function() for i, player in pairs(Players:GetPlayers()) do local success, error = pcall(function() coinsStore:SetAsync(player.UserId, player.Cash.Value) winsStore:SetAsync(player.UserId, player.leaderstats.Wins.Value) killStore:SetAsync(player.UserId, player.leaderstats.Kills.Value) deathStore:SetAsync(player.UserId, player.leaderstats.Deaths.Value) end)
if not success then warn("Error while setting data") warn(error) end end
end)