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

how would i go about adding points to a player that kills another player with an explosion?

Asked by
Donut792 216 Moderation Voter
5 years ago

ok so i have a script inside of a bomb that of course creates an explosion but it also creates a value of the player who placed it which both work fine but i am trying to figure out a way to make the game add points to a player that kills another player or players with said explosion

script that makes the owner value and clones the bomb

game.ReplicatedStorage.DropBomb.OnServerEvent:Connect(function(Player,Spot,RootPart)
    local Bomb = game.ReplicatedStorage.BombBag
    local Clone = Bomb:Clone()
    Clone.Parent = workspace
    Clone.Position = RootPart.Position - Vector3.new(3,0,0)
    local Owner = Instance.new("StringValue")
    Owner.Parent = Clone
    Owner.Value = Player.Name
end)

localscript that that tells the server to make the bomb

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local RootPart = character.HumanoidRootPart
local Spot = RootPart.Position
local BombDropped = false
game:GetService("UserInputService").InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.F then
            if not BombDropped then
                BombDropped = true
                game.ReplicatedStorage.DropBomb:FireServer(Spot,RootPart)
                wait(5)
                BombDropped = false
            end
        end
    end
end)

sorry im not good at wording things

0
Just like you assigned an Owner value, use that check in your explosion event or whatever way you’re doing the damage. If the value is the same, then alter their leaderstats from there. ABK2017 406 — 5y
0
not sure how i would do that tho something like when a player is killed check which Owner value was in the bomb that killed them but im not sure how to go about scripting that Donut792 216 — 5y

2 answers

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago

I don’t have time to write it all but assuming that leaderstats and player has been added, you would add something like this, obviously changing “money” and it’s “value” to whatever. If you then add some lines in your damage script, explosion, bullet damage whatever, you can choose under what conditions to meet that will award the owner. This is sort of a really long comment but too big for comments. I will try to expand on the damage and checking the value when I can if it’s not answered.

char.Humanoid.Died:Connect(function()
    If char.Humanoid:FindFirstChild(“creator”) ~= nil then 
    local Tag = Instance.new(“StringValue”)
    tag.Value = char.Humanoid.creator.Value
    local Give = game.Players:FindFirstChild(Tag.Value)
    Give.leaderstats.money.Value = Give.leaderstats.money.Value + 100
    Tag:Destroy()
    end
end)
Ad
Log in to vote
0
Answered by
crywink 419 Moderation Voter
5 years ago
local function getCharacter(desc)
    while desc do
        if desc:FindFirstChildOfClass("Humanoid") then
            return desc.Parent
        end

        desc = desc.Parent
    end

    return nil
end

-- ...

local explosion = Instance.new("Explosion")

explosion.Hit:Connect(function(hit)
    local character = getCharacter(hit)

    if character then
        local creator = Instance.new("ObjectValue")
        creator.Name = "creator"
        creator.Value = playerWhoCreatedExplosion
        creator.Parent = character
    end
end)

explosion.Parent = workspace

All that's left is to connect a function to the Died event of a player character's Humanoid upon spawn and have it check the character model for an ObjectValue object pointing the killer

Answer this question