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

Money Per Kill Script Gives the Killed Player Money?

Hi, this script is supposed to give the player who killed another player money, however the player who died is the one who gets it. Any reason why this is?

game.Players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "leaderstats"
	local currency1 = Instance.new("IntValue",folder)
	currency1.Name = "Gold"
	
	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
					character.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 10
				end
			end
		end)
	end)
end)

1 answer

✓ Accepted answer

1)Don't use free scripts 2)Why are you checking in character for the leaderstats? 3)You're supposed to be using the tag's value to find the player. 4)Indent


local reward = 0.001 --lol

game.Players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "leaderstats"
	folder.Parent = player
	local currency1 = Instance.new("IntValue")
	currency1.Name = "Gold"
	currency1.Parent = player

	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag ~= nil then
				if game.Players:FindFirstChild(tag.Value) then
					game.Players[tag.Value].leaderstats.Gold = game.Players[tag.Value].leaderstats.Gold + reward
				end
			end
		end)
	end)
end)

1 comment

0

Nevermind, ignore #4

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