Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need help with cash on kill script which is not working?

Im trying to do this script where when you kill someone, you get cash, im trying to do it without making a new folder, but its not working, can someone help me.

game.Players.PlayerAdded:connect(function(player) local folder = "leaderstats" local currency1 = "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)

1 comment

0

wait 5 mins Ill answer

2 answers

✓ Accepted answer

When you say "without making a new folder", I am assuming that you have already made the folder so. on lines 2 and 3, you identify the variables "folder" and "currency1" as strings. You then later attempt to access the value from it. But you can't because it's a string. I think you meant to access the strings from the actual player

game.Players.PlayerAdded:connect(function(player)
	local folder = player:WaitForChild("leaderstats") -- waiting for the CHILD leaderstats IN the player, not just a string 
	local currency1 = leaderstats:WaitForChild("Cash") -- assuming that cash is in leaderstats, waiting for a child named "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 -- you can now access the value, since the variable is an actual instance rather than a string
				end 
			end 
		end) 
	end) 
end)

If that does not work, then see if anything is coming up in the output

1 comment

1

ty

Heres the script I used

game.Players.PlayerAdded:connect(function(player)
 local leaderstats = Instance.new("Folder",player)
 leaderstats.Name = "leaderstats"
	
 local currency1 = Instance.new("IntValue",leaderstats)
 currency1.Name = "Money"
 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 + 100 --This is the reward after the player died.
    end
   end
  end)
 end)
	local kills  = Instance.new("NumberValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("NumberValue", leaderstats)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		
		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
			local tag = humanoid:FindFirstChild("creator")
			local killer = tag.Value
			if tag and killer then
				killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			end
		end)
	end)
end)

there's also deaths and kills

This discussion is preserved as it was. New answers, comments, and votes are closed.