I Searched Everywhere And I Cant Find A Script That Adds The Cash To The Gui ,Can Someonw Help Me please ? Sorry if I am not correct of what I am talking, I am new to Scripting
Does someone have a script money on kill on npc that adds the cash to a gui not leaderboard ?
1 answer
This is how I would do it. So first i made a tool to attack the npc, just a part for the handle this is the script inside the tool
local debounce=false
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")~=nil then
local human=hit.Parent:FindFirstChild("Humanoid")
if debounce==false then
debounce=true
hit.Parent:FindFirstChild("attacker").Value=game.Players:GetPlayerFromCharacter(script.Parent.Parent)
human:TakeDamage(10)
wait(1)
debounce=false
end
end
end)
this damages the npc and sets the attacker value inside to the player, this is important, i put an object value inside the npc called attacker, so when the npc dies it will give cash to the attacker. now cash is inside leaderstats, inside a folder in leaderstats called Stats, reason being we dont want to show the cash on a leaderboard, since you said you want it as a gui. Next is the script inside the npc model.
local debounce=false
script.Parent.Humanoid.Died:Connect(function()
if debounce==false then
debounce=true
local player=script.Parent.attacker.Value
if player~=nil then
player.leaderstats.Stats.Cash.Value=player.leaderstats.Stats.Cash.Value+math.random(25,35)
end
script.Parent:Destroy()
end
end)
so the player gets cash when they kill the npc with the tool. Then we need to add the leaderstats to the player, with this script in serverscript service:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats=Instance.new("Folder")
local Stats=Instance.new("Folder")
local Cash=Instance.new("IntValue")
leaderstats.Name="leaderstats"
Stats.Name="Stats"
Cash.Name="Cash"
Cash.Parent=Stats
leaderstats.Parent=player
Stats.Parent=leaderstats
end)
then because you want it in a gui, we make the gui and textlabel to display the cash value, since adding numbers to the text property of gui would be wierd.
while wait() do
local leaderstats=game.Players.LocalPlayer:WaitForChild("leaderstats",60)
script.Parent.Text="$".. tostring(leaderstats.Stats.Cash.Value)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
the gui or leaderstats
Add the money to the gui not leaderboards
bro you said have a cash value, a gui's text holds a string meaning you have to convert to a string and to a number, you have no solid amount of money, just a thing displayed in gui
know what you are doing, find the text in which you want to change the value, assign a value, set the text to that value, must be local, example: val = 1 label.Text = "money: "..val