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.
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)