Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I have help awarding money to a player for every kill?

Asked by 10 years ago

I need to figure out a way to award money to the player who kills one of the aliens in my game, I want to be able to award 25 for each kill, but I want ti to go the that one player, does anyone have any idea? If you have a place where I could go to, that would be great, if anyone could explain to me the basics of how I would do this, that would be greatly appreciated.

1 answer

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

This depends on how the weapons are scripted, but in most weapons, there is code to add a 'creator' tag to the Humanoid that the weapon is damaging. So to detect who killed what alien, you'd probably have something like this.

local Players = Game:GetService("Players")

function AlienKilled(alien, killer)
    print(killer.Name .. " killed an alien.")
    -- award points to `killer`
end

function AlienDied(alien)
    local tag = alien:FindFirstChild("Humanoid"):FindFirstChild("creator")
    if tag and tag.Value then
        AlienKilled(alien, tag.Value)
    end
end

function AlienSpawned(alien)
    alien:WaitForChild("Humanoid").Died:connect(function()
        AlienDied(alien)
    end)
end

Workspace.ChildAdded:connect(function(child)
    if child:IsA("Model") and child.Name:lower() == "alien" then
        AlienSpawned(child)
    end
end)
0
I am pretty sure I mentioned I want it to only count when the player kills the alien. rollercoaster57 65 — 10y
0
By the looks of this script, it will only work when a player kills another player. rollercoaster57 65 — 10y
0
Ah, I misunderstood then. Basically the same concept though. I'll make an edit. Ekkoh 635 — 10y
0
okay, thank you. This will be great, becuase I don't want players to have to buy money for upgrades... So would I put this in the weapon script? rollercoaster57 65 — 10y
0
I would put this in ServerScriptService. Ekkoh 635 — 10y
Ad

Answer this question