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

How do I increase a player's score when they kill something?

Asked by 6 years ago
Edited 6 years ago

Hello, I am having trouble figuring out a way to increase a value in a script in the player's ScreenGui. What I need to do is detect who the player is who dealt the lethal blow to the enemy (or even better, whoever dealt the most damage) and then increase their money value by an amount, but I really know how to detect if the enemy died or who killed it. Thanks.

EDIT: I'm going to post the code that I have for the player's balance of money.

local Players = game:GetService("Players")
local ThePlayer = nil

function onPlayerAdded(player)
    ThePlayer = player
    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Value = 166
    Coins.Parent = script
    if ThePlayer.PlayerGui.ScreenGui ~= nil then
      ThePlayer.PlayerGui.ScreenGui.CoinAmount.Text = Coins.Value
    end
end


--When a player joins, call the onPlayerAdded function
Players.PlayerAdded:connect(onPlayerAdded) 

--Call onPlayerAdded for each player already in the game
for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

while true do
    script.Coins.Value = script.Coins.Value + 1
    ThePlayer.PlayerGui.ScreenGui.CoinAmount.Text = script.Coins.Value
    game.ServerStorage.CoinGet:Play()
    wait(1)
end

For testing purposes, the amount of coins is increased by one every second.

0
Not enough detail. Atleast post the script so we can modify it :/ come on dude, we aren't gods you know.. AyeJude 41 — 6y
0
That's the problem, I don't have a script for this because I don't know how to do it, which is why I am asking. bludud1234 40 — 6y

1 answer

Log in to vote
0
Answered by
AyeJude 41
6 years ago
game.Players.PlayerAdded:connect(function(player)
 local folder = Instance.new("Folder",player)
 folder.Name = "leaderstats"
 local currency1 = Instance.new("IntValue",folder)
 currency1.Name = "Cash"
 player.CharacterAdded:connect(function(character)
  character:WaitForChild("Humanoid").Died:connect(function()
  local tag = character.Humanoid:FindFirstChild("creator")
   if tag ~= nil then
    if tag.Value ~= nil then
     currency1.Value = currency1.Value + 10 --This is the reward after the player died.
    end
   end
  end)
 end)
end)

0
No, I meant when a player kills an npc such as a zombie or something, but this looks like it is related to a player dying. bludud1234 40 — 6y
0
Just edit the script to be compatible with a npc, if you still can't do that, I guess I can whip up a script real quick. AyeJude 41 — 6y
Ad

Answer this question