Hello, it has been a minute since I have used the forum, and since I have took a shot at scripting so im quite confused. My friend and I are trying to create a simple game in which we implemented KOs and WOs. The guns that we like do not add kills to the leaderboard. Since it has been a while since I have tried any scripting, I dont know where to start.
Currently inside the weapon are 3 scripts. I figure I have to make a creator tag for it but not sure which script to go into nor how to go about it. Below is a weapon for example.
Basically, I would like to understand how to make a creator tag that will add kills to the leaderboard for these weapons, and if I should make the code inside one of the three scripts listed above or in its own separate script, under the weapon. Thanks for any and all help.
Could you look through all the scripts, find one that uses :TakeDamage or just subtracts the Humanoid health, and send it here?
The goal is to deal damage, detect if their health is now below 0, and if it is, increment their kill count and increment the person they killed’s wipeout count.
After using the ctrl + f to find it, theres only one match at the top of the code in this photo. I included some of the code below that, but heres a photo of code above incase needed.
local function _defaultDamageCallback(system, target, amount, damageType, dealer, hitInfo, damageData)
if target:IsA(“Humanoid”) then
target:TakeDamage(amount)
end
end
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
if not target or ancestorHasTag(target, “WeaponsSystemIgnore”) then
return
end
if IsServer then
if target:IsA(“Humanoid”) and dealer:IsA(“Player”) and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass(“Humanoid”)
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if dealerHumanoid and target ~= dealerHumanoid and targetPlayer then
– Trigger the damage indicator
WeaponData:FireClient(targetPlayer, “HitByOtherPlayer”, dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
-- NOTE: damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
-- ..The default weapons pass in that data
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
end
local function _defaultDamageCallback(system, target, amount, damageType, dealer, hitInfo, damageData)
if target:IsA("Humanoid") then
target:TakeDamage(amount)
end
end
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
if not target or ancestorHasTag(target, "WeaponsSystemIgnore") then
return
end
if IsServer then
if target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if dealerHumanoid and target ~= dealerHumanoid and targetPlayer then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
-- NOTE: damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
-- ..The default weapons pass in that data
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
end
end
I’ve added the functionality and some comments. By the way, the :GetState check can be changed to a Health < 0 check, but I believe :GetState should be more accurate.
Code:
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
if not target or ancestorHasTag(target, "WeaponsSystemIgnore") then
return
end
if IsServer then
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if targetPlayer and target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
if dealerHumanoid and target ~= dealerHumanoid then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
-- NOTE: damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
-- ..The default weapons pass in that data
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
-- Check if target is dead
if targetPlayer and target:GetState() == Enum.HumanoidStateType.Dead then
-- Give dealer a kill
dealer.leaderstats.Kills.Value += 1
-- Give target a death
targetPlayer.leaderstats.Death.Value += 1
end
end
end
I’ve changed it to a health check. Could you test this code and tell me what it prints?
Code:
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
if not target or ancestorHasTag(target, "WeaponsSystemIgnore") then
return
end
if IsServer then
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if targetPlayer and target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
if dealerHumanoid and target ~= dealerHumanoid then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
-- NOTE: damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
-- ..The default weapons pass in that data
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
print("Health remaining: ".. target.Health)
-- Check if target is dead
if targetPlayer and target.Health <= 0 then
-- Give dealer a kill
dealer.leaderstats.Kills.Value += 1
-- Give target a death
targetPlayer.leaderstats.Death.Value += 1
end
end
end
Did the gun even function in the first place? And are you 100% sure that is the only place where it does damage? Also, are you sure you set your output so that it displays everything and not just certain scripts?
What do you mean by function in the first place? In this case I am using an RPG, when I fire it, it either does splash damage on the player or kills the player. And is there anything else I can refer to instead of _defaultDamageCallback to answer your second question?
This is also under the weapon, do you need to see any of these?
By the way, that gun pack is just a copy of official Roblox weapons:
I would recommend using the Roblox version, just incase the one you sent me has bad code.
It also wasn’t your fault why these problems happened. It was because there are multiple copies of that code, some of which were overriding each other.
Here’s the fix:
Grab the WeaponsSystems folder from any gun, and drop it into ServerScriptService. Only do this once. No need to delete duplicates either.
Edit the WeaponsSystem module script in that folder, and change the WeaponsSystem.doDamage function to this:
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
if not target or ancestorHasTag(target, "WeaponsSystemIgnore") then
return
end
if IsServer then
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if targetPlayer and target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
if dealerHumanoid and target ~= dealerHumanoid then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
-- NOTE: damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
-- ..The default weapons pass in that data
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
-- Check if target is dead
if targetPlayer and target.Health <= 0 then
-- Give dealer a kill
dealer.leaderstats.Kills.Value += 1
-- Give target a death
targetPlayer.leaderstats.Death.Value += 1
end
end
end
If I use the roblox version of these weapons, will I still have to change the code? I assume still that I would have to move the WeaponsSystem to ServerScriptService still.