generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: When a humanoid dies, how would you find the killer?

Previous Thread :: Next Thread 
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 07:37 AM
I'm making a script where irt awards cash if you kill someone.
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 07:42 AM
bump
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 07:48 AM
bump.
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 07:52 AM
You guys are supposed to help. What is the line?
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
03 Dec 2011 07:57 AM
local tag = humanoidLfindFirstChild("creator")

Creator is an invisible value that pops up inside a humanoid when it dies, it says who killed it.
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 08:04 AM
You would use it with respawn right?
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
03 Dec 2011 08:07 AM
here's a hint: Read the linked leaderboard, and change it(copy and paste the code in another script inorder to edit it) so it can award cash instead of wos and kos.
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 08:10 AM
Wil, I like to do things on my own. I don't like to copy and paste stuff that I didn't make.
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
03 Dec 2011 08:11 AM
copy and paste to help you code it, so you know you won't have errors in your copy and delete the copied code as you go.
Report Abuse
CosmicEpicMii is not online. CosmicEpicMii
Joined: 24 Apr 2010
Total Posts: 138
03 Dec 2011 08:13 AM
Yeah, well otherwise, we cant help you. Just use the linked leaderboard;) (Yes. Im not BC, but I used to play and i had a pretty good game. Just checking on Roblox, seeing whats going on ;P)
Report Abuse
rangersmash is not online. rangersmash
Joined: 18 Nov 2009
Total Posts: 2891
03 Dec 2011 08:22 AM
[ Content Deleted ]
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
03 Dec 2011 08:41 AM
Well, Wil. This is what I have.


game.Players.PlayerAdded:connect(function(p)
wait(.1)
    ldr = Instance.new("IntValue")
    ldr.Name = "leaderstats"
    ldr.Parent = p
    stuff = Instance.new("IntValue")
    stuff.Name = "Cash"
    stuff.Value = 50
    stuff.Parent = ldr
end)
function onHumanoidDied(humanoid, player)

        -- do short dance to try and find the killer

        local killer = getKillerOfHumanoidIfStillInGame(humanoid)

        handleKillCount(humanoid, player)
    end

function onPlayerRespawn(property, player)
    -- need to connect to new humanoid
    
    if property == "Character" and player.Character ~= nil then
        local humanoid = player.Character.Humanoid
            local p = player
            local h = humanoid
            humanoid.Died:connect(function() onHumanoidDied(h, p) end )
    end
end

function getKillerOfHumanoidIfStillInGame(humanoid)
    -- returns the player object that killed this humanoid
    -- returns nil if the killer is no longer in the game

    -- check for kill tag on humanoid - may be more than one - todo: deal with this
    local tag = humanoid:findFirstChild("creator")

    -- find player with name on tag
    if tag ~= nil then
        
        local killer = tag.Value
        if killer.Parent ~= nil then -- killer still in game
            return killer
        end
    end

    return nil
end

function handleKillCount(humanoid, player)
    local killer = getKillerOfHumanoidIfStillInGame(humanoid)
    if killer ~= nil then
        local stats = killer:findFirstChild("leaderstats")
        if stats ~= nil then
            local kills = stats:findFirstChild("Cash")
            if killer ~= player then
                kills.Value = kills.Value + 10
                
            else
                kills.Value = kills.Value - 10
                
            end
        end
    end
end


(It doesn't work)
Report Abuse
rangersmash is not online. rangersmash
Joined: 18 Nov 2009
Total Posts: 2891
04 Dec 2011 04:11 AM
[ Content Deleted ]
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
04 Dec 2011 06:37 AM
Just use this in the character :P
script.Parent.Humanoid.Died:connect(function()
tag = script.Parent.Humanoid:findFirstChild("creator")
if creator then
if creator.Value then
creator.leaderstats.Points.Value = creator.leaderstats.Points.Value + 10
end
end
end)
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
04 Dec 2011 09:48 AM
@su8 FAIL!!!!!!! 2 reasons for the fail. 1. creator.leaderstats = errors
2. Object value can't be used to get something it's impossible.
Report Abuse
Darkcheez is not online. Darkcheez
Joined: 22 Oct 2008
Total Posts: 157
04 Dec 2011 10:16 AM
It has to be a feature of the weapons. Look in the rocket launcher, slingshot, or other default weapon.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image