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