is there a efficient way to make a kill script? i have a kill script but it gives u the value if ur ability hits a A.I when their health is 0
but its kinda inefficient and i head the creator aka tag system doesnt work anymore and was deprecated in 2015
On all of my kill scripts, I just have it set the health to 0 of course, If I need to ad a value to a player like a Kill to the leaderboard, I often to it inside of the script. If you don’t want to do health to 0, you can delete the head, break the joints, etc.
So how do you know what player killed the A.I? i dont really understand what you mean haha
Like the damage script that actually takes the damage. Like this.
Here is one for a simple sword,
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health > 0 then -- Checking to see if its even a player
if not hit:IsDescendantOf(script.Parent.Parent) -- Checking to see that it aint touching the character that is holding the sword
hit.Parent.Humanoid = 0
game.Players:GetPlayerFromCharacter(script.Parent.Parent).leaderstats.Kills = game.Players:GetPlayerFromCharacter(script.Parent.Parent).leaderstats.Kills + 1
end
end
end)
In order to detect which player attacked the A.I., you’ll need a HitArray
(which is a table). Whenever a player attacks the A.I., the table is added with the player’s name.
When the A.I. dies, return the table to script.
I fail to understand your query. Please make it comprehensible and make it clear as to what you want.
If you want to add a ObjectValue referencing the Player who killed the Victim, then you’d need to check if the health of the Victim’s Character is greater than one.
The easiest way would be, whenever the player gets hit, a objectValue referencing the player who attacked them is added/updated. Then, when the player’s health is 0, you can reference that value.
By detecting who killed the AI, it would be by putting a value from it’s humanoid and naming the value as what the player’s name is.
By kill script, Humanoid:TakeDamage() can be used from this.
One thing you could also do to make a kill brick is to break joints on touch. Basically, no matter whatever they try to do to bypass it, it automatically breaks the joints inside the character forcing and auto OOF.
Hopefully that helps
Edit: (Just realized you meant if hitting A.I. well, you could use breakjoints for other uses as a kill script if needed just as boundaries, lava, etc.)
Well that depends on your use case and the way you craft your game. There can’t be an “efficient way” to make a kill script without a use case being provided. You also need to think about how you’re integrating that code with other game systems as well. There’s already enough ways to kill humanoids. Off the top of my head,
- Setting Humanoid health to 0 (doesn’t work if Health is clamped)
- Setting the Humanoid’s state to Died
- Destroying the Torso or Head of a character, or displacing it
- Removing a joint related to either of the two above limbs
- Calling BreakJoints on the model
Not really. There’s still games out there that listen for the Died event. Not sure where you get the impression that’s inefficient. How are you expecting to check for Humanoid death? You can listen for a change to the Died HumanoidStateType as well, I suppose.
Wasn’t deprecated. The creator tag system was quite literally a tagging system that was intended to tag humanoids to be able to determine who was involved in a Humanoid’s damaging (or death). That was fully ported in Lua - what was deprecated was the KOs count on a user’s profile being incremented from those creator tags.
Creator tags still work, though that’s up to the developer how to modify. You can also create your own tagging system just as easily and not use ValueObjects. It’s completely up to you how you go about it.
In terms of handling death counts, I would advise against using the solution that 12904 proposed. You should handle death states and incrementing of data from the Humanoid itself, whether you have a module system or each NPC has a script. Your tools should only be concerned with carrying out their specific functions, not handling data where it shouldn’t be.
-- Script in the NPC, directly descending the model
local Debris = game:GetService("Debris")
-- You can hard code the Humanoid's name here, since it shouldn't change
local Humanoid = script.Parent:WaitForChild("Humanoid")
Humanoid.Died:Connect(function ()
-- Check for tags
-- Increment stats of players who tagged the humanoid
end)
-- Let's assume that tags are added to the Humanoid
Humanoid.ChildAdded:Connect(function (Child)
-- Sample code
if Child:IsA("ObjectValue") and Child.Name:lower() == "creator" then
-- Destroy the added item after 5 seconds
Debris:AddItem(Child, 5)
end
end)
-- Script in the Tool, directly descending the Tool
local Tool = script.Parent
local Handle = Tool.Handle -- I believe it's implicitly available
Handle.Touched:Connect(function (Hit)
-- Perform checks on Hit to see if it's a Humanoid or whatever
-- Create a tag value and add it to the Humanoid
end)